Helo. I’m making a spaceship system that steers with the mouse. I use an AlignOrientation (the replacement for the bodygyro), to turn. It works well, however it only turns on the Y axis (Left to right).
The AlignOrientation is on OneAttachment mode. It has a maxtorque of 50000, and a responsiveness of 5. Its MaxAngularVelocity is infinite. All other important settings (PrimaryAxisOnly, ReactionTorqueEnabled, and RigidityEnabled) are set to false.
My code for calculating the AlignOrientation’s CFrame is shown below. (MousePos being Mouse.Hit.Position)
The video below shows how the ship only turns from left to right. I would also like it to turn up and down, so the ship can move properly. If there is any info I am missing, please let me know.
Seems like it’s trying to move up, but the baseplate is stopping it from rotating upwards - try posting a video of you attempting to rotate it upwards without something blocking the way (perhaps with gravity disabled?)
Unable to repro your problem - Tried your script on a part in studio and it seems to work just fine with the X and Y axes. If gravity is off, maybe try moving the ship a bit further up? (If the ship is spawning on the SpawnLocation, move it upwards, anchor, and turn collision off). If that doesn’t work, it must be a problem with your ship.
Here’s what I wrote to get your code working in studio:
game.Players.LocalPlayer:GetMouse().Move:Connect(function()
local MousePos = game.Players.LocalPlayer:GetMouse().Hit.Position;
local PrimaryPos = workspace.Part.Position;
local direction = (PrimaryPos - MousePos).Unit;
local bg : AlignOrientation = workspace.Part;
bg.CFrame = CFrame.new(PrimaryPos, PrimaryPos + direction);
end)
Hi. Thank you. I had been doing the code on a server script via remote function. I didn’t know that it would be replicated. I guess something with the remote function was messing it up. This fixed it.
Actually, there is one more thing. It turns up and down fine, however it doesn’t turn to a good enough angle. It tilts up/down, but not very far or quickly. Any idea? I basically did that code you did there.
In the video shown, you can see that it does turn, however I would like the turns to be a bit stronger.
Mouse.Move:Connect(function()
local MousePos = Mouse.Hit.Position
local PrimaryPos = Ship.PrimaryPart.Position
local direction = (PrimaryPos - MousePos).Unit
local bg : AlignOrientation = Ship.PrimaryPart.Turn
bg.CFrame = CFrame.new(PrimaryPos, PrimaryPos - direction)
end)
One thing I forgot to mention is that in the final setting of the CFrame, I did change HRPPos + direction to HRPPos - direction, because that made it so the turns weren’t inverted anymore.
On second thought, I’ve decided on a solution. I’m just going to make it so turns are sharper if the ship isn’t accelerating, and have turns be less sharp if moving. Thank you for all the help.
With RigidityEnabled set to true, turns are instant - if you want to make it a more gradual change, look into changing the AlignOrientation’s MaxTorque, MaxAngularVelocity, and Responsiveness.