- Home /
move player to its rotating direction?
i want to move object to it's rotation direction like if object is rotate right side then its move in right side , if object is rotate left side then its move in left side, if object is rotate forward side then its move in forward side,if object is rotate backward side then its move in backward side. and also add force to that direction.(like angry bird game bird is going to up and then down angry bird is 2d game but i have 3d (like flyboard)).so please give me some ideas for that.
Answer by Ellie97 · Jul 24, 2018 at 09:44 AM
hi Elli97 i want to make like flyboard like this video link texthttps://www.youtube.com/watch?v=m4Bm3cs9TFo
Answer by TheKnightsofUnity · Jul 24, 2018 at 11:37 AM
Hello @Jasmin1347!
First of all, we would like to advise you to set the velocity of an object at first. If you are using 3D space - declare a Vector3 variable which will be your vector of movement.
Vector3 velocity = transform.forward; //Example velocity vector
Next, set a normalized vector of velocity to see the direction vector of length equal to 1. Just in case.
Vector3 direction = velocity.normalized;
Finally, for setting rotation of an object, use a transform.rotation and set it to Quaternion.LookRotation(direction);
transform.rotation = Quaternion.LookRotation(direction);
You can find a full example at: https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html
Your answer
Follow this Question
Related Questions
Update speed and physics makes my rigidbody jiggle 2 Answers
Prevent Rigidbody From Rotating 3 Answers
Roll a ball camera problem? 1 Answer
making perpetual movement 1 Answer
Foces only change during collision 1 Answer