

Then you can set the rigidbody - thisRigidbody.AddForce (force, ForceMode.Acceleration) Var rotationAngle = AngleAroundAxis (transform.forward, turnDir, Vector3.up) ĪngularVelocity = (Vector3.up * rotationAngle * turningSmoothing) Make the character rotate towards the target rotation Then we can calculate the angular velocity Vector3 deltaVelocity = targetVelocity - thisRigidbody.velocity įorce = deltaVelocity * accelerationRate Vector3 targetVelocity = nextDirection * speed Vector3 nextDirection = (b - a).normalized Assuming you have 2 vectors, point a the position of the game object, b the position of the target to move to. Here's a typical rigidbody movement motor. I use this in movement of some robot characters and needed more than just a simple Lerp. If you're movement is physics based you can calculate the angular velocity. Also remember to search for your issue, searching for "Unity 2D Forward" came up with this helpful answer: Show more comments It is also generally better to ask a new question ins$$anonymous$$d of commenting on an answer on another if you need help. If you are new to Unity and want to make a 2D game I recommend you to start with some of the 2D tutorials which covers many of these things: In 2D the Up and Right direction will always have a Z value of 0 which means that it can safely be ignored and passed into the $$anonymous$$ovePosition function. So in 2D you want to use the UP or Right direction ins$$anonymous$$d: transform.up. In 2D you cannot move forward because forward is in the direction of the Z Axis which is into the screen. You are casting a Vector3 (transform.forward) into a Vector2 which basically just removes the Z value of the Vector3. Transform.Rotate(0, ltaTime * counterClockwise, 0)

Transform.Rotate(0, ltaTime * clockwise, 0) Rigidbody.position += Vector3.right * ltaTime * movementSpeed Rigidbody.position += Vector3.left * ltaTime * movementSpeed Rigidbody.position += Vector3.back * ltaTime * movementSpeed Transform.position += Vector3.forward * ltaTime * movementSpeed So how can I make it always go forward based on the front of the cube? Any help would be much appreciated. It doesn't matter what direction it is facing. When I rotate it though, it still goes the the same direction when I press a directional button. I have a cube that is my player and I can move it with WASD.
