zektonn
(zektonn)
July 16, 2022, 11:45pm
#1
What’s the best way to go about making the turret aim at the mouse position?
Currently I’m using body gyro inside the turret with cylindrical constraints and then making
the body gyro, every heart beat, to look at the mouse position, like so:
Remote.OnServerEvent:Connect(function(player, mouse)
gyro.CFrame = CFrame.new(turret.Position ,Vector3.new(mouse.X, mouse.Y, mouse.Z) )
end)
The remote is wrapped in a run service function in a local script.
How would I do this using align orientation?
Or is there a better way to rotate things? like CFrame?
I want to change methods because body gyro can be very buggy at times also its deprecated.
Rapideed
(mang)
July 17, 2022, 12:20am
#3
Use CFrame.LookAt.
gyro.CFrame = CFrame.lookAt(turret.Position , mouse.Hit.Position )
Also you should use UserInputService instead of mouse.
https://developer.roblox.com/en-us/api-reference/datatype/CFrame
1 Like
zektonn
(zektonn)
July 17, 2022, 12:45am
#4
I don’t want to use gyro because its deprecated. Are there any other methods?
darthubz
(Darthubz)
July 17, 2022, 1:03am
#5
Maybe check and make sure the axis is correct? I can’t give you a detailed explanation because you don’t provide any video of this alleged “glitch” of the gyro?
Rapideed
(mang)
July 17, 2022, 2:17am
#6
Oh I thought the part name was gyro mb. So basically change the turrent’s cframe to that.
Turrent.CFrame = CFrame.lookAt(turret.Position , mouse.Hit.Position )
zektonn
(zektonn)
July 17, 2022, 6:48am
#7
There is no “glitch”, I’m simply looking for another way to rotate the turret that doesn’t include body gyros, because they are deprecated.
Try this:
Turret.CFrame = CFrame.new(turret.Position, mouse.Hit.Position)
zektonn
(zektonn)
July 17, 2022, 8:12am
#9
Would this work with cylindrical constraints?
No. it does not work with cylindrical constraints, you will need a regular part to do this
zektonn
(zektonn)
July 17, 2022, 8:39am
#11
I’m looking for a method which works with constraints as the turret will be attached to a vehicle.
zektonn
(zektonn)
July 18, 2022, 7:09am
#12
How could I make this work for 2 parts? like 1 part controls the x and z axis, while another part controls the y axis?
You should try to union them⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
zektonn
(zektonn)
July 18, 2022, 12:35pm
#14
I don’t want the entire turret to move on the y axis, only the actual cannon part should move on the y axis