x


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

more ▼

asked Dec 28 '11 at 09:00 AM

tatelax gravatar image

tatelax
131 11 20 23

(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest

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;

more ▼

answered Dec 28 '11 at 09:38 PM

qbert65536 gravatar image

qbert65536
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

If you take a look at this function you may get something to proceed further!?!?!

http://unity3d.com/support/documentation/ScriptReference/Terrain.SampleHeight.html

more ▼

answered Dec 28 '11 at 11:38 AM

flamy gravatar image

flamy
3.5k 5 11 37

Naah, that won't work. Thanks though.

Dec 28 '11 at 04:54 PM tatelax
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x956
x353
x46

asked: Dec 28 '11 at 09:00 AM

Seen: 453 times

Last Updated: Dec 28 '11 at 09:38 PM