I am trying to move an object in a particular direction based on the angle it’s aimed in with a script like this-
LocalVelocity = (transform.InverseTransformDirection (rigidbody.velocity));//Get the current local velocity
rigidbody.AddRelativeForce (Vector3(-(LocalVelocity.x),0,0), ForceMode.VelocityChange);// ad a negative x local velocity to keep moving in the direction it's aimed
This works great and the object will go in the direction it’s pointed in, but…
Part of my game mechanic requires me to be able to rotate the object around on the y axis(to aim), but since you can never actually apply a clean y euler rotation on a rigid body I’m not sure how to get the aiming part to work right.
I thought that maybe I could have an object that sits on top of the rigidbody gameobject (in the hierarchy) but I couldn’t run transform.InverseTransformDirection on that as there is no rigidbody.velocity to base it’s direction on.
Does anyone have any ideas on how I could do this? I’ve been banging my head against a wall for weeks on this now, I really didn’t think it would be this hard.
Pete.