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

Make an enemy follow along a wall

$
0
0
I have a 3d tile based map. I am trying to get an enemy to follow the wall of a room (either the wall on it's left or right consistently per enemy). ![Path for enemy][1] [1]: /storage/temp/111068-path.jpg The yellow line above is only indicative of direction and movement, it should still move to the tiles and trace around the outer walls. The code I have will turn around ok when it hits a wall, but will still cut across the room even if there is a path around the outside. void Update() { transform.LookAt(moveDestination); if(transform.position.x == moveDestination.x && transform.position.z == moveDestination.z) { isMoving = false; } else { isMoving = true; } if(isMoving == false) { RaycastHit hit; if(Physics.Raycast(transform.position,transform.forward,out hit,scale)) { if(Physics.Raycast(transform.position,-transform.right,out hit,scale)) { transform.LookAt(transform.position + (-transform.right * scale)); } else { transform.LookAt(transform.position + (-transform.right * scale)); } } else { moveDestination = transform.position + (transform.forward * scale); } } } void FixedUpdate() { transform.position = Vector3.MoveTowards(transform.position,moveDestination,moveSpeed * Time.deltaTime); }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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