Hey, first post on here, I’m curious about how I would achieve this.
What I have setup currently is a cube that moves forwards, and rotates using addforce and addtorque. What I’d like to achieve is when there is a current force that’s applied to the game object (When a vertical inpuit is held) and the cube is then rotated; the force will continue on based on the front of the cube. Rather than just slide towards where the previous force was pushing to. Similar to how a car would move.
Excuse this rough drawing, but a visual representation may help convey the idea.
The code I currently am using is this.
rb.AddForceAtPosition((Input.GetAxis("Vertical") * forwardForce * transform.forward), transform.position + addForceLocation, ForceMode.Force); rb.AddRelativeTorque(Vector3.up * (Input.GetAxis("Horizontal") * turnForce), ForceMode.Force);
Add a forward force when the vertical input is pressed, times by the desired force in a forward direction, in the root of the rigid body plus the offset.
Rotate torque on the Y axis, by the desired force times by the horizontal input