I'm sorry if this is a little bit long but here's my code: Also here's my place here. You also need to hold right click for moving your ship to work, so yeah. There's no errors, it just acts strangely.
local UIS = game:GetService("UserInputService")
local spaceship = workspace:WaitForChild("SpacePart")
local gyro = spaceship:WaitForChild("BodyGyro")
local ang = spaceship:WaitForChild("BodyAngularVelocity")
gyro.MaxTorque = Vector3.new(0,0,math.huge)
local speed = 200
local yRot = 0
local xRot = 0
UIS.InputChanged:connect(function(input)
print("Input changed.")
if input.UserInputType == Enum.UserInputType.MouseMovement then
print(input.Position)
print(input.Delta)
xRot = input.Delta.x * 1000-- + xRot
yRot = input.Delta.y + yRot
gyro.CFrame = CFrame.Angles(0, 0, math.rad(-yRot))--CFrame.Angles(input.Delta.x,input.Delta.y,input.Delta.z)
ang.AngularVelocity = Vector3.new(0, math.rad(-xRot), 0)
end
end)
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.A then
local velocity = Instance.new("BodyVelocity", spaceship)
velocity.Name = "VelocityA"
velocity.Velocity = spaceship.CFrame.lookVector * speed
end
if input.KeyCode == Enum.KeyCode.D then
local velocity = Instance.new("BodyVelocity", spaceship)
velocity.Name = "VelocityD"
velocity.Velocity = spaceship.CFrame.lookVector * -speed
end --
if input.KeyCode == Enum.KeyCode.S then
local velocity = Instance.new("BodyVelocity", spaceship)
velocity.Name = "VelocityS"
velocity.Velocity = (spaceship.CFrame * CFrame.Angles(0, math.pi/2, 0)).lookVector * speed --Thanks to SH!
end
if input.KeyCode == Enum.KeyCode.W then
local velocity = Instance.new("BodyVelocity", spaceship)
velocity.Name = "VelocityW"
velocity.Velocity = (spaceship.CFrame * CFrame.Angles(0, math.pi/2, 0)).lookVector * -speed --Thanks to SH!
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
local badVelocity = spaceship:FindFirstChild("VelocityW")
if badVelocity then
badVelocity:Destroy()
end
end
if input.KeyCode == Enum.KeyCode.S then
local badVelocity = spaceship:FindFirstChild("VelocityS")
if badVelocity then
badVelocity:Destroy()
end
end
if input.KeyCode == Enum.KeyCode.A then
local badVelocity = spaceship:FindFirstChild("VelocityA")
if badVelocity then
badVelocity:Destroy()
end
end
if input.KeyCode == Enum.KeyCode.D then
local badVelocity = spaceship:FindFirstChild("VelocityD")
if badVelocity then
badVelocity:Destroy()
end
end
end)
I hope somebody can help, I can't figure out why it's doing this.
