Game Development Community

How can I get an object to rotate around and shoot if he's pointed at the player?

by Nathan Meier · in Torque Game Builder · 01/12/2013 (1:46 am) · 3 replies

I'm trying to make this enemy type for a game which is an object that clockwise/ counter clockwise by itself, and if he happens to be facing in the direction of the player, he fires a bullet. But I have no idea how to go about doing that. Would there be anyone here who could maybe give me some advice? Any help would be greatly appreciated!

#1
01/12/2013 (7:16 pm)
You could do a raycast ... a thread on it here may help. Worth doing a search on this and see what other examples there are.

The ray cast would point in the direction, based on the values, if the ray cast detects the player, then fire a weapon at it. You'll need some other values, like the id of the source_enemy and target_player or target_ai
#2
01/12/2013 (7:20 pm)
and a bit about rotations
#3
01/13/2013 (9:50 am)
This is what I would do.
Just make sure that the enemy has the id of the player is any variable you want. For encapsulation I assume it's in a personal variable.

if(%this.getRotation() == t2dAngleToPoint(%this, %this.playerID))
{
   %this.shootBullet();
}

I'm not sure but that might produce the effect of shooting at the direct opposite of the player so you might either have to switch the order of parameters in the "t2dAngleToPoint" or have something like "%this.getRotation()+180".