Something small but usefull is the String.Format function, with which you can format your numerical outputs: using System; using System.Collections; … debugText += String.Format(“HR{0:000.000}\n”, shoulderRHeading);
Here’s something that will calculate where two lines will intersect. If they don’t intersect then the two resulting vectors will mark the points where both lines are closest together. /* setup vectors */ Vector3 l1begin = playerCurrentPosition; Vector3 l1end = playerTargetPosition – l1begin; Vector3 l2begin = enemyCurrentPosition; Vector3 l2end = enemyTargetPosition – l2begin; /* calculate [...]
If you want to have an object turn automatically towards a target then you have to find out in which direction to turn. The usual angle function just returns the smallest angle between the current heading and the heading towards the target but not which way around. Vector3 lTarget = transform.InverseTransformPoint(target.position); targetDistance = lTarget.magnitude; targetAngle [...]
September 13, 2011 – 10:39
To get the vector from a quaternion rotation you simply multiply the quaternion by the forward vector. Debug.DrawRay(transform.position, transform.rotation * Vector3.forward, Color.red); This also effectively rotates the forward-vector with the rotation of the transform, positioning it relative to the rotation of the actual object.
September 13, 2011 – 10:38
I’m getting a bit fed up having to look up everything with google when programming. Therefore I’ll add everything I need and find here (even if it isn’t all that extrodinary).