Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

2D enemy to move within level not over it

$
0
0
Hi I am using a basic bit of code to make an enemy I have within a game to follow after the player, however it doesn't move within the level it moves over it not colliding with anything. here is the code I am using: var Player : Transform; var MoveSpeed = 4; var MaxDist = 10; var MinDist : float = 0.5; function Start () { } function Update () { //transform.LookAt(Player); if(Vector3.Distance(transform.position,Player.position) >= MinDist) { //transform.position += transform.forward*MoveSpeed*Time.deltaTime; transform.position += (Player.transform.position - transform.position).normalized* MoveSpeed* Time.deltaTime; if(Vector3.Distance(transform.position,Player.position) <= MaxDist) { } } } if anyone knows an easy way to make it move within the level that would be great. Also sorry if the code is bad or the question is bad I am very new to this.

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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