- Home /
AddForce Relative to Rotation
While I know this question has been asked a lot, mine is different than most of the others. :(
Well I'm attempting to figure out AddForce, and I'm having the common "addforce relative to direction" problem. Since I have four different directions (WASD), I can't exactly just say, "transform.forward * speed"
Here's my current AddForce:
move is a Vector3 that has the values according to the speed I want to go, AKA:
move = new Vector3(speed, 0, -speed);
The move
values are generated based on userinput; If the user press "W", move.z changes. ;)
Here's my code ATM:
rigidbody.AddForce(new Vector3((move.x - rigidbody.velocity.x) * 0.5f, move.y, (move.z - rigidbody.velocity.z) * 0.5f), ForceMode.VelocityChange);
Any ideas?
Sometimes answers can take days. Have patience young padawan lol. I'll look over your code and see if I can't come up with something.
Answer by MD_Reptile · Nov 15, 2014 at 10:55 PM
Maybe have separate move variable per direction. Like MoveLeft / MoveUp... Then instead of trying to change it based on input, just switch according to input to the direction that corresponds with movement key. Like if (Input.WhateverGoesRight){Move = MoveRight} and then apply the force.
Good luck!
Every good script I've ever written started out as a bad hack haha.
Your answer
Follow this Question
Related Questions
Move Player Car in Forward Direction using Physics Force 1 Answer
How can I move an object a specific distance using AddForce? 2 Answers
relativeVelocity how to? (noob question) 2 Answers
Using rigidbody.AddForce and speeding the object 2 Answers
relative velocity of rigidbody according to rotation... 1 Answer