Need help creating turret for my game

I am trying to create turrets similar to those in starscape (video attached) and am not sure how to approach this. I have tried using a combination of CFrame and hinges but I could not get it to work.

2 Likes

If you wanna go for player controlled turrets, I’d honestly skip hinges cuz they’re tricky to sync and can get clunky fast, CFrame is the way to go. :happy3:
You can rotate the turret using CFrame.lookAt based on the player’s mouse.Hit.Position just get the turret’s base position & then point it towards the mouse hit and if you want it smoother, you can Lerp between the current CFrame and the target one.​
I’ll link these for u to read

Thank you for the response! This does help me a lot, but I would also like the base to rotate along with the barrel and I’m just not quite sure how I would do that?

1 Like

You can just change the base’s Y axis, and change all of the barrel’s axis, since CFrame:LookAt() only returns the cframe of the object, and does not completely change it.

1 Like

I guess that would work, but I also don’t know how I could do all of this on a moving platform. Would I be able to just weld the turret to the platform and it would still rotate normally using cframe?

1 Like

You can just use the CFrame angles of the returned cframe, so yes, you can simply just weld it, atleast from what i know.

1 Like

Alright I will give it a try. Thank you for the help.

2 Likes

Luckily enough I made a turret in a test place a short while ago with a simple script and only using hinges, here is the place file. It aims where your mouse goes.

its uncopylocked

3 Likes