Rotating a Rigid Body and moving Forward

``````var yTurn = 0; //adjusted left/right arrow
var zSpeed = 0; // adjusted by up/down arrow
var playerMarble : GameObject; //marble object
var playerMove : gameObject;  // empty game object that is used for movement of all children

playerMarble.transform.RotateAround(playerMove.transform.position, Vector3.up, yTurn);

``````

Here is a bit of the code I'm using to move and rotate my marble. The move forward works, the rotation works, but the move forward always move one direction no matter where it's rotated. So even if I rotate it 90 degrees it still moves forward in the original direction before the rotation.

What I'd like is the rotation to determine which direction the force is added. I thought forward would always move on the Z axis which is what forward would be. Any help would be great.

OK your problem is simple. You in add force you put Vector3.forward, OK so thats rong because the Vector3 moves in the vectors it mines it dosent matter how you rotate it dosent go the forward you want so you need to change Vector3.forward to transform.forward

Forward is an absolute value not a relative one which is the information you asked for. Getting such a value can be achieved by giving the force over the same axis the same force but added with the rotation of the object.

Say the object is rotated 90 degrees around the Y axis and faces (absolute) right. That means adding force forward (absolute value) will increment the force in the angle of the axis itself without the rotation (0 value). Simply add the rotation value to the force