I have a certain condition in which a gameObject can be moved only in x axis.I am using mouse x delta change as input (Input.GetAxis(“Mouse X”)) multiplied by some sensitivity. i have defined boundary value for x, so that it is clamped.
the problem is that the gameObject moves some values greater than boundary value then resets back to boundary position. it is not stopping immediately at that point.
- using physics calculations in Fixedupdate().
- moving using rigidbody.MovePosition() method.
Try the suggestion below. For bullet projectiles, just use hitscan and create a fake bullet effect either with a particle system or line renderer etc. ---------- For larger projectiles, such as rocket launchers or grenades (or if you also want bullets with colliders), you can do a sweep test (as suggested below), and before you move the projectile forward, raycast a certain distance forward, and if it hits something, teleport it to the hit pos, as to ensure that it doesn't move through walls (if it is really fast).
– Llama_w_2Ls