AddForce Relative to Rotation

While I know this question has been asked a lot, mine is different than most of the others. :frowning:


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. :wink:

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?

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!