- Home /
How would I confine an object to the ground?
Hello,
I am developing an AI system. Currently, I am doing this:
transform.position = Vector3.MoveTowards(transform.position, player.position, moveSpeed * Time.deltaTime);
Works great, until the player goes at a higher point then the enemy...
How can I make it so that the enemy does not fly upwards towards the player?
THANKS
Answer by flamy · Dec 28, 2011 at 11:38 AM
If you take a look at this function you may get something to proceed further!?!?!
http://unity3d.com/support/documentation/ScriptReference/Terrain.SampleHeight.html
Answer by qbert65536 · Dec 28, 2011 at 09:38 PM
You could also use Mathf.Clamp or a static '1' on the Y axis , in the above example,
var newPos = "move towards".
newPos.y = 1; transform.position = newPos;
Your answer
Follow this Question
Related Questions
SphereCastAll sees for miles 2 Answers
Too Close To The Trap and melee attacking enemys. 1 Answer
Adding Distance in javascript 2 Answers
Make Navmesh agent follow closest object with tag 0 Answers
Adding a load level to this script. 1 Answer