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.
2 Answers
2Take a look at BurgZerd Arcade’s Hack ‘n’ Slash tutorial series. One of the first videos has exactly what you need.
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.
}
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.
– paingel13Did you actually try searching for Burgzerg Arcade ???? I mean, it's pretty famous, any search engine would find it. * http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial * http://www.youtube.com/playlist?list=PLE5C2870574BF4B06
– AlucardJay