- Home /
How to get enemies to slowly approach first person controller
Hi im trying to make a script in which the enemies will slowly approach the player and will give me a variable on the speed to help control the enemy in later levels.
Answer by Cherno · Nov 21, 2013 at 06:41 PM
Take a look at BurgZerd Arcade's Hack 'n' Slash tutorial series. One of the first videos has exactly what you need.
http://www.burgzergarcade.com/tutorial/unity-game-engine-tutorial-hs2-001
I watched the video but i couldnt find the second part of it and the first video didnt go over much except importing assets from the store.
Did you actually try searching for Burgzerg Arcade ???? I mean, it's pretty famous, any search engine would find it.
Answer by push_over · Dec 19, 2013 at 05:03 PM
Without an example of your current code and showing us where you're having troubles, the best we can practically do is show you a tutorial (like Cherno did above) and give you a bit of pseudo code.
private Vector3 _direction;
// create a new Vector3 for the direction we need to go to get to the player.
public float movementSpeed = 10.0f;
// this will be how fast your enemy moves toward the player.
void Update(){
_direction = playerObject.transform.position - transform.position;
// calculate the direction. thankfully, it's very simple
// within the unity engine by simply subtracting your enemy's
// position from the player's position.
transform.Translate(_direction, movementSpeed * Time.deltaTime);
// this does the actual movement. multiply movementSpeed
// by deltaTime to make movement framerate independent.
}