#Help with Scripting a turret

1 messages · Page 1 of 1 (latest)

floral pier
#

Well unfortunetly i am very bad at scripting that i needed to use chatgpt to make this script so...
my turret does this weird stuff and some guy on my last post told me to change the CFrame to AlingPostition but he didn't specify it

what i am looking for is for my turret to be looking towards where my mouse is pointing at and to be able to shoot... havent tried that

i will do my best to cooperate with you guys to help me fix this problem.

full trench
#

Are you moving the entire turret?

You should use lookAt for the CFrame, but the origin parameter should be where the turret is already

but only the barrel should be changed, the stand can be still

If the entire turret needs to rotate, use lookAt to get the rotation (.Rotation) but sanitize it by changing the non-y axis values to 0

pallid tartan
#

idk anything about this

#

but do you use hinges

floral pier
pallid tartan
#

i don't think its code, but does ur turret have multiple parts?

floral pier
#

Yes

floral pier
full trench
# floral pier Barrel is just an union of everything on the top then under the barrel is the ro...

The reason why it's being weird is that you're just sending the entire turret to your mouse's position.

But you don't want the turret to move, just rotate

So to do that, we'd want to make parts of the turret point to the mouse.

CFrames are a structure that contains position and rotation. 3D objects have a CFrame.

CFrame has a constructor called lookAt, which creates a new CFrame that would make the object move so it's at the origin position, and point, or rotate, towards the given position.

If you have a rotator, you can use lookAt to have it look at the mouse.

But since lookAt can also change position, you have to give that function the rotator's current position so it doesn't move, but still looks at the mouse.

So rotator.CFrame = CFrame.lookAt(rotator.CFrame.Position, mouse.Hit)

https://create.roblox.com/docs/reference/engine/datatypes/CFrame#lookAt

floral pier
full trench
floral pier
#

the plasma (Blue thing) welded to the barrel (the upper gun), the barrel welded to the rotator (the little block under barrel), and the rotator jointed to base (The circle under there) because i saw it did the same thing if i welded also.

full trench
floral pier
#

i need to anchor the rotator to something i believe because if don't weld it to smth then it will fall down

full trench
floral pier
#

i edited the script you told me i copy pasted the script up there and the targetPos comes from the getting aim script

#

wait hold up, is C0 same thing as part0?

#

local script on the left script on the right

full trench
floral pier
#

💀 i am so unexperienced my bad

full trench
floral pier
#

ill think about it

full trench
floral pier
#

like? 🤨