# enemies ignoring gravity?¿

Ok, so i added a script to an enemy in my game to make him follow the player. But now they are completely ignoring gravity and floating straight toward the player. I have tried many things and cant get them to lock on to the player and still be affected by gravity. Help please. Thank you in advance for any help.

So we’re not sure what your script to follow does.

Nor do we know how you make your character is controlled by gravity (are they rigidbodies, or are the character controllers that are manually updated for gravity).

Whichever it is, however your follow script is implemented, it overrides how the gravity is applied. Stop that. Work along with it.

Thank you, i will try to see what the problem is, if i cant figure it out i will post my code.

#pragma strict
var target : Transform; //the enemy’s target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var myTransform : Transform; //current transform data of this enemy
Physics.gravity = Vector3(0, -20, 0);
function Start ()
{
target = GameObject.FindWithTag(“Player”).transform; //target the player
}

function Update () {
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);

//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}

function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}

Firstly your Physics.gravity = Vector3(0, -20, 0); is outside any function. Can you do that in US?
Secondly, there is nothing that actually puts the object on the ground or makes them use gravity.
All your code does is rotate and translate the object, which obviously will make it float towards the rotation.
Easiest method would be to put a character controller and then use CC’s Move function with gravity to move the object.

Of course you can use a rigidbody but that would require a lot more scripting and for the most part would serve no purpose.

Please use [plain]``[/plain] tags when pasting code.

Thank you very much, I didnt even think of that.

I added a cc and now i cant drag my enemies around anymore. I had to get my backup from dropbox because it wouldnt go back even after i removed the cc, why?

Ok, just to clear it up, the use gravity box was unchecked. -.-