local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local TurretUnion = game.Workspace.Turret.TurretS
while wait() do
TurretUnion.CFrame = TurretUnion.CFrame * CFrame.Angles(math.asin((mouse.Hit.Position - mouse.Origin.Position).Unit.Y), 0, 0)
end
I tried to make a loop that detects the mouse position and faces the turret towards it, however something doesn’t work.
The first Vector3 is the position, the second Vector3 is the LookAtPosition;
I suggest doing this client-sided and server-sided (client-sided for the player who is doing it, server-sided for other players)
Also you would have to move the script into the player’s playerscripts for it to run, i would clone the script and remove the clone upon sitting down and sitting up since it seems you want to do that as you put it in the seat.
Quick question… I’ve been trying to make it rotate only in one axis
Is there a way to lock some axis orientation or making it just rotate in one direction?
local unit = (mouse.Hit.Position-turret.Position).Unit
local cross = unit:Cross(Vector3.new(0,1,0))
turret.CFrame = CFrame.fromMatrix(turret.Position,cross, Vector3.new(0,1,0))
Not sure if I should ask my own questions on here… But…
I’m making a mech, and using this, I made it rotate towards the mouse! The problem is… It rotates, and MOVES towards the mouse at the same time. Do you have a fix on this? (The first one, by the way)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local turret = game.Workspace.TurretUnion
while wait() do
turret.CFrame = CFrame.new(turret.Position, Vector3.new(mouse.Hit.Position.X,turret.Position.Y,mouse.Hit.Position.Z))
end
I have almost not even coded in a while so i’ve forgoten a lot of things but I tested the code and it didnt make it go forward so it might be something in your game.