- Home /
Changing direction without altering velocity
Im making a tribes style game (if you need context to my question) and i want you to be able to slightly control you direction when going at high speeds. The players rotation is independent of the direction you are going so i cant use the "side to side" axis. How should i go about this? Should i make an item that follows the players travelingdirection and base it on that or is there any other way. Like using rigidbody.velocity or something...
This is hard to answer without knowing how something turns. You can do something like this:
rigidbody.velocity = Quaternion.AngleAxis(10.0 Time.deltaTime) transform.up) * rigidbody.velocity;
If this is applied every frame, you will see a 10 degree change in direction every second while maintaining the current velocity. Best if this line was executed in FixedUpdate(). If you want to keep some fixed speed, you can change the line to:
rigidbody.velocity = Quaternion.AngleAxis(10.0 Time.deltaTime) transform.up) * rigidbody.velocity.normalized * someSpeed;
Could you describe the exact effect you're after. You're correct that it'll involve changing the linear velocity of the rigid body, but to work out what to change it by we need to know what effect you want.
Velocity incorporates a speed in a direction. Where
Speed = Distance / Time,
Velocity = Displacement / Time.
Just being a pedant, but your title is erroneous.
But it is owing to this that Velocity can be expressed in a Vector3. This makes it very easy to change direction but maintain speed. Normalise your direction vector and multiply it by your speed.
Answer by LSPressWorks · Aug 26, 2014 at 05:40 PM
If I gather you are describing where, for instance the playing is running left, and can turn to the side while he continues to run along the same path leftward?
Is the motion being applied directly to the player, or is the player the child of an object that is producing the movement?
For stuff like that I drop the player in an empty object to apply velocities so that I can apply rotation to the character without it affecting directional speed. Thus the player can flop and rotate around all day under the controller object, while actual directional force is only applied to the controller.
you can "clip" the effect with an if statement to check the speed, and if I understand you correctly, turning radius decreases with speed? If that is the case you can you can divide your rotation factor by a portion of the velocity such as
//--Check to see if we're above 92 velocity--//
if(controllerObject.velocity.magnitude.normalized >= 92)
{
//--Decrease turning sp with increase in relation to velocity above 92--//
rotSpeed = rotSpeedBase / ((controllerObject.velocity.magnitude.normalized -92) / 5);
//--reset to normal turning sp when under target speed--/
}else
{rotSpeed = rotSpeedBase;}
Bear in mind, that you may need to check with some if statements to be sure that you don't go under any problematic limits, like 0 when doing stuff like this.
Your answer
Follow this Question
Related Questions
Change the direction of velocity upon tapping a button!!?? 1 Answer
Final direction and velocity of two velocities [World Velocity and Local Velocity] 0 Answers
How to change pace by pressing different buttons once? 1 Answer
How do I script speed in java? 0 Answers
how to change pitch of sound without changing speed? wav file 1 Answer