Hello Unity community !
I want a sphere which moove in direction of camera forward.
That work but when the speed is too high, the drift effect is too strong.
When i turn my camera to the right, the sphere need a couple of second to move on camera.forward.
The huge problem is to compensate the forces, when you turn, to obtain a more reactive gameplay.
Im trying to compensate that with the if(), when cam.transform.forward.x between 0 and 1 we turn to the right, if i increase the force value maybe i can compensate the centrifugal effect.
I have also try Force.Impulse mode
// This script is on my sphere player
void FixedUpdate ()
Vector3 mouvment = cam.transform.forward;
if(cam.transform.forward.x != 0) // right if positive, else left
rigidbody.AddForce(mouvment * speed * Time.deltaTime);
My first suggestion is to up the drag of the rigidbody. The higher the drag, the faster the old velocity will decay and the sooner the new velocity will take hold. You may have to up the amount of force you apply (speed in your code above) to compensate for the drag.
If that is not fast enough, then you can directly assign the velocity. Something like:
rigidbody.velocity = cam.transform.forward * speed;
This will cause an immediate change in velocity. Note that you don’t need multiply by deltaTime inside of FixedUpdate. When inside FixedUpdate, Time.deltaTime will actually be Time.fixedDeltaTime which is a constant.
@Pyassin’s suggestion is to only modify the rigidbody.velocity when the camera turns. The code could look like:
float mag = rigidbody.velocity.magnitude;
rigidbody.velocity = cam.transform.forward * mag;
This causes an immediate turn but preserves the speed going into the turn.
If you want the thing to turn and remain the speed without it still having a force act on the original rotation (like it would irl) save the magnitude that is before turning then set velocity to 0 and then regive it the velocity in the direction you want with the old magnitude.