- Home /
My enemies stack and do not use gravity
I Am making a fps shooter when my enemies follow me they stack and don't use gravity I have all the stuff you need for a enemy and they are prefabs this is the script //set the values in the inspector public Transform target; //drag and stop player object in the inspector public float within_range; public float speed; private float time; public void Update() { if(time == 1f) { //get the distance between the player and enemy (this object) float dist = Vector3.Distance(target.position, transform.position); //check if it is within the range you set if (dist <= within_range) { //move to target(player) transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed); } //else, if it is not in rage, it will not follow player } time = Time.timeScale; }
Answer by Stactic_Games · May 18, 2020 at 09:25 PM
who ever answers with best answer I will respond to their next question if possible
Answer by Quickz · May 18, 2020 at 10:08 PM
If you want to have gravity available for an object, you need to add a RigidBody component. Also if you gonna move an object with that component, you probably want to move the object by changing the object's velocity.
Here are a couple of references:
https://docs.unity3d.com/ScriptReference/Rigidbody.html
https://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html
An extra note:
If you gonna modify the velocity, try to do that in a FixedUpdate method.
Your answer
![](https://koobas.hobune.stream/wayback/20220612234653im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enemy behavior help 1 Answer
Trigger gravity by external collider 2 Answers
No gravity when running against a wall (2D) 1 Answer
How do I “freeze” an object after a collision? 3 Answers
Spline Interpolator + FPS Walker? 0 Answers