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

Enemy movement towards an instanced target position

$
0
0
Hey, everyone! So what I'm trying to do is have an enemy that randomly moves around, casting rays to search for the target. Upon finding that target, I'd like for the enemy to charge the position at which the ray hit the player--that single point--until it collides with something (at which point a 3-second cooldown is activated). The problem I'm having in my current script is that, if the player moves while the enemy charges, it will follow the player until collision. Given the nature of the enemy, I would like to use LookAt if possible to have it rotate towards that ray point, but it's not totally necessary right now. This is what I came up with: if (canSeeTarget()){ this.transform.LookAt(target.transform); rigidbody.AddRelativeForce(0,0,150); rigidbody.drag = 4; velocity = base_velocity * 150; }else{ base_velocity.x = Random.Range(1f, 10f); base_velocity.y = Random.Range(1f, 10f); base_velocity.Normalize(); velocity = base_velocity * speed; } applyVelocity(); For your information, base_velocity is a protected Vector2, and the canSeeTarget(){ just uses a RayCast function which returns as true if it hits the player. Thanks for your help!

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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