Hello.
I’m making an aircraft, specifically focused right now on how to make it bank.
When the player sits in cockpit, the Camera mode turns to FirstPersonLocked.
I use UserInputService:GetMouseDelta() to get a change in pixels to determine whether or not the mouse is on the right or left side of the screen.
RSS.RenderStepped:Connect(function(Delta)
local delta = UIS:GetMouseDelta()
print(Mouse.Hit.X)
previousMouseHit = Mouse.Hit
print(previousMouseHit.X)
--print(Mouse.Hit.X - previousMouseHit.X)
if EngineActive then
if MouseDirectionOn and not TaxiActive and not VTOLActive then
local CC = BankAngle(Mouse)
if delta.X > 1 then
script.Engines.Value.Parent.MainBodyPart.BodyGyro.CFrame = Mouse.Hit * CFrame.Angles(0,0,-45)
TurnAngle = -45
elseif delta.X < -1 then
script.Engines.Value.Parent.MainBodyPart.BodyGyro.CFrame = Mouse.Hit * CFrame.Angles(0,0,45)
TurnAngle = 45
else
if TurnAngle > 0 then
TurnAngle = TurnAngle - 1
elseif TurnAngle < 0 then
TurnAngle = TurnAngle + 1
elseif TurnAngle == 0 then
TurnAngle = 0
end
script.Engines.Value.Parent.MainBodyPart.BodyGyro.CFrame = Mouse.Hit * CFrame.Angles(0,0,TurnAngle)
end
-- print(CC)
LThrust.Velocity = script.Engines.Value.Parent.MainBodyPart.CFrame.LookVector * ThrustAmount
RThrust.Velocity = script.Engines.Value.Parent.MainBodyPart.CFrame.LookVector * ThrustAmount
formerMouseHit = Mouse.Hit
elseif TaxiActive then
--script.Engines.Value.Parent.MainBodyPart.BodyGyro.CFrame = CFrame.new(script.Engines.Value.Parent.MainBodyPart.Position, Vector3.new(script.Engines.Value.Parent.MainBodyPart.Position.X + YawAmount, script.Engines.Value.Parent.MainBodyPart.Position.Y, script.Engines.Value.Parent.MainBodyPart.Position.Z))
script.Engines.Value.Parent.MainBodyPart.BodyGyro.CFrame = CFrame.new(script.Engines.Value.Parent.MainBodyPart.Position, Vector3.new(Mouse.Hit.p.X, script.Engines.Value.Parent.MainBodyPart.Position.Y, Mouse.Hit.p.Z))
LThrust.Velocity = script.Engines.Value.Parent.MainBodyPart.CFrame.LookVector * ThrustAmount
RThrust.Velocity = script.Engines.Value.Parent.MainBodyPart.CFrame.LookVector * ThrustAmount
elseif VTOLActive then
if VTOLActive and MouseDirectionOn then
script.Engines.Value.Parent.MainBodyPart.BodyGyro.CFrame = CFrame.new(script.Engines.Value.Parent.MainBodyPart.Position, Mouse.Hit.p)
elseif VTOLActive and not MouseDirectionOn then
script.Engines.Value.Parent.MainBodyPart.BodyGyro.CFrame = CFrame.new(script.Engines.Value.Parent.MainBodyPart.Position, Vector3.new(Mouse.Hit.p.X, script.Engines.Value.Parent.MainBodyPart.Position.Y, Mouse.Hit.p.Z))
end
else
script.Engines.Value.Parent.MainBodyPart.BodyGyro.CFrame = CFrame.new(script.Engines.Value.Parent.MainBodyPart.Position, formerMouseHit.p)
LThrust.Velocity = script.Engines.Value.Parent.MainBodyPart.CFrame.LookVector * ThrustAmount
RThrust.Velocity = script.Engines.Value.Parent.MainBodyPart.CFrame.LookVector * ThrustAmount
end
end
Plr.Character.Humanoid.CameraOffset = Vector3.new(0,30,60) --0,30,60
end)
The problem I have you can see in the following video -
Whenever I stop moving the mouse, the aircraft starts to stutter.
Picture of the Output print of TurnAngle.
It is shown to be decreasing whenever I’m not moving the mouse, and then goes back to Angle 45 whenever I turn.
Can you print out the final TurnAngle of the ship? It would help to narrow down exactly what part of the scirpt/variable is causing the stutter. If you can print out the TurnAngle, do you notice any extreme changes in between prints in the TurnAngle? If so, that’s the culprit. It’d also help if you posted a screenshot of the output too.
@laughablehaha Thanks for the reply!
Edited the question, along with a picture of the output. The TurnAngle performs exactly like the script should do, there are no extreme changes if you discount the times when I move my mouse to either side to continue the turn. (Which is planned.)
I’m using RenderStepped, maybe the values are going too fast?
I don’t think it should make a difference, if anything it should make it smoother I believe.
Upon second thought, this behavior seems to be due to one force attempting to tilt the ship, and another different force interfering with the first force attempting to keep the ship upright, causing a stutter effect. I would double check the outputs of your BodyGyros.
Also, try setting your MouseFilter = workspace just to rule out another bug.
Somewhere in your code: Mouse.MouseFilter = workspace
This will make it so Mouse.Hit won’t hit any invisible parts or any parts of your ship which might be the culprit. Let me know how it turns out!
My MouseFilter is set the model of the aircraft.
And I’ve actually got 2 BodyVelocity’s that move the aircraft forward (It uses LookVector of parts that always face forward). Could this be one of the problems causing the glitch? The BodyGyro is the only thing that controls the direction of where it goes.
I had an idea to move this inside each if statement, since then I guess the transition of it would be smoother when the If Statement values change?
Yes, try to use only one BodyVelocity for vehicle’s movement and see how that works. BodyVelocity and other “Body” objects are deprecated and thus the physics engine no longer treats nor supports these objects like they used to. However, one BodyVelocity instead of two should get the job done.
Sorry for the late response. Did what you asked, still the same problem. I don’t think it was affecting the BodyGyro in the first place since both of the BodyVelocities were in different parts, but facing the same direction.
Try using a simpler version of this aircraft and see if the amount of parts is the issue. You never really know because the physics engine in roblox is weird.
Try this:
1)Instead of using Mouse.Hit, use the CFrame of the camera(when adjusting the BodyGyros, to be specific.). This will localize everything which may possibly fix the issue
2) Increase/Descrease the TurnAngle at smaller intervals. I would do TurnAngle += 0.1 and TurnAngle -= 0.1. See if that smoothens it out.
3) Put prints INSIDE the if, elseif, and else statement, and watch what the output prints as the ship stutters.