gun turret "activation" and target finding.

I have a gun turret which rotates around it’s center point to follow the player. It does so by checking the angle between player and turret each frame and adjusting accordingly.

Initially I need the turret to be dormant and when the player is within a certain distance it activates and rotates to follow the player. However, I can’t quite figure out how to transition between the dormant-active stage and the general rotation to aim at the player.

Has anyone tried to do anything like this before and how did you go about it?

I’m not asking for anyone to code my solution, just for some ideas on approach.

I’ve already got the turret working, shooting, recoiling, it’s draggable and so on, so I just need a hand with smoothly aquiring the player as a target, then switching to the general aiming function.

Dan [import]uid: 67933 topic_id: 24596 reply_id: 324596[/import]

line or rect and when it collides with the enemy or player target is in range…
hope this helps a bit… [import]uid: 86417 topic_id: 24596 reply_id: 99609[/import]

I have a sample of something where I have a square in the center of the screen, and it’s a pivot joint. Whereever you point to the turret points there instantly.

As far as the detection, you could do something like if player.x and y is within x and y pixels to turret or you could just use a isSensor (like a bigger circle that overlays the “turret” and whenever a player comes within range and touches that sensor, the turret would activate.

I can imagine what you are doing and I can cook up an example pretty quick, however I am about to get on the road so that will have to wait :slight_smile:

let me know if what I said makes sense. I think the way to go is if you have a circle in the middle of screen with a radius of 50, then a second circle that is say 150 or 200 (whatever radius you need) and is set to isSensor = true, you can use that to trigger. Now the trickery would come in is WHERE on the circle they touched, so you could do something like when player touches the sensor, turrent points to player.x and y using some sort of function.

That was a lot of info :slight_smile: haha.

-Nick [import]uid: 61600 topic_id: 24596 reply_id: 99610[/import]

Hi Guys and thanks for your input so far.

I’m not sure if I explained myself very well initially so will try and better highlight the issue.

First off, my turret already does all of the following:

1, both turret and target object are draggable.
2, I have a function which measures the angle between the turret and target every frame.
3, The distance between the objects is also measured per frame. When distance < 150 this calls the shoot function.
4, when in range shoots a bullet every 1500ms at the correct angle and velocity, and the barrel recoils.

The next stage is to wire up an invisible collision area, (such a “cone of sight”) and when the target object collides with it, the shoot() function is called. I can do this myself, just explaining how the final thing will work.

The issue with this approach is that the turret will initially be dormant or inactive. When the player/target object collides with the “cone of sight” the turret will play through a little animation and become active/awake. This involves rotating towards the player and the barrel extending out of the body etc.

It’s how to transition between the turret becoming awake and aquiring the target object/rotating to match it, and then switching to the general rotating to follow the target/player that I’m having trouble with.

Does that make sense? (probably not)

Again, thanks for your help so far, it’s much appreciated.

Dan [import]uid: 67933 topic_id: 24596 reply_id: 99793[/import]