Download

Gun Turret on Space Ship

Hi,
here is my setup: I have an spaceship wich can be rotated around all three axis, on this ship there are several similar gun turrets. These gun turrets have two parts the base and the gun, which are rotating on only on axis.
Now i have copied several Blueprint from tutorials on youtube and they work fine if I dont rotated the Ship.

My Question now is how to implement the turret in a way that i can rotate the ship how i want and the turret rotating and aiming in the right way.

Islidius

Make turret separate blueprint. Then add to spaceship as child actors.

You need some way of communicating with turrets:
Turrets need either interface, or connect to dispatcher (that is created by ship).
Then you update list of targets from that dispatcher or interface.
Each turret gets list of targets as array of locations.

Now you need some logic for turrets to pick their best targets.
So for each turret calculate vector from root of turret to its target.
You have 2 vectors: forward vector of turret and vector to target. Normalize that target vector and calculate dot product of forward turret and target. If that dot product (its cosinus) is in some range (like 0.8 to 1) that means target is in cone of around 20deg ahead of turret. So it can shoot that target.
When turret can shot target you should rotate it (with interpto). To rotate turret use “look at rotation”. You have your current turret rotation and vector to target. Jus do not rotate root of turret (you need this to calculate forward vector). Instead rotate turrets mesh.
Last is checking if turret is aiming at target (or in some tight range, again use DOT product). So if target is like +/- 2deg then fire.

what should I do if I want all the turrets to point at the mouse crosshair while moving the ship to other directions?