Quantcast
Channel: Answers by "2d4Games"
Viewing all articles
Browse latest Browse all 24

Answer by 2d4Games

$
0
0
As for moving to where the player currently is as opposed to where it was, you should implement a check to see what his position is at every frame. You can then change the position of the enemy gradually using a velocity variable. (Code is in Unityscript, I don't know C# unfortunately :P) var player : Transform; //Set this variable in the main unity editor var posX = transform.position.x - player.transform.position.x; var posY = transform.position.y - player.transform.position.x; var velocity = Vector2(0,0); var movementAngle = Mathf.Atan(posY/posX); velocity.x = Mathf.Cos(movementAngle); velocity.y = Mathf.Sin(movementAngle); transform.position.x += velocity.x * Time.deltaTime; transform.position.y += velocity.y * Time.deltaTime; That code is a very basic way of getting the enemies to move towards the character. What exactly do you mean about moving with a curve?

Viewing all articles
Browse latest Browse all 24

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>