Search Unity

Resolved Bug : impacts moving with the movements of my gun

Discussion in 'VR' started by christDuNord, May 9, 2021.

  1. christDuNord

    christDuNord

    Joined:
    Oct 24, 2020
    Posts:
    26
    Hello.
    I am a beginner and I am testing for FPS with Oculus using a Gun and a raycast with impacts.
    But I have a problem with my impacts moving with the movements of my gun.

    I attached a gun to one of the hands, I use a raycast for shooting and collisions. All of them work except that the impacts, instead of remaining fixed at their point of impact, follow the movement of my gun!

    It's like the raycast stayed on and the impact continued to follow it!

    Anyone have any idea of the problem?

    Thanks for your help.
     
  2. christDuNord

    christDuNord

    Joined:
    Oct 24, 2020
    Posts:
    26
    My script :

    ray.origin = raycastOrigin.position;
    ray.direction = raycastOrigin.forward;

    var tracer = Instantiate(tracerEffect, ray.origin, Quaternion.identity);
    tracer.AddPosition(ray.origin);

    if(Physics.Raycast(ray, out hitInfo)){
    tracer.transform.position = hitInfo.point;

    if(hitInfo.collider.gameObject.tag == "Levier collider")
    {
    impactMetal.transform.position = hitInfo.point;
    impactMetal.transform.forward = hitInfo.normal;
    impactMetal.Emit(1);
    } else {
    impactOther.transform.position = hitInfo.point;
    impactOther.transform.forward = hitInfo.normal;
    impactOther.Emit(1);
    }
    }
     
  3. christDuNord

    christDuNord

    Joined:
    Oct 24, 2020
    Posts:
    26
    I found the problem.
    You had to select "world" in the particle settings.