1
\$\begingroup\$

I have an object that moves towards another object using this line :

transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime);

this is it's attributes:

enter image description here

It doesn't use gravity, kinematic and it's Y position is frozen, but it keeps falling to the floor and colliding with it. How do prevent that and keep it floating ?

\$\endgroup\$
1
  • \$\begingroup\$ Doesn't make sense that it should fall given your configuration. Are you sure it's the correct object? Could it be that the object has a parent object that also has a rigidbody, and that one does use gravity? Also, where is the target's position? Do you actually see it moving towards the target at all, or just falling down? \$\endgroup\$
    – tbkn23
    Apr 26 '15 at 8:15
0
\$\begingroup\$
transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime);

You do know that if the target's position is on the ground, then your object's position will also try to match the objects's Y position. You can try to make an object and check all the constraints, and it will still work if you give it a Translate script, because scripts tend to override constraints.

If you want to make your object go to the target, but still keep his Y position, you could just make a new target vector :

new Vector3(target.transform.position.x, this.transform.position.y, target.transform.position.z);

and make this the target, so your objects keeps his Y position since he's already in it, and translates on the XZ-plane instead.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .