Hello fellow devs, I am currently making a game that requires the car to rotate a certain way while in the air. when W is held, the car should face down, and when S is held, the car nose should point up, kind of like a plane. However, my method only works when the car faces a certain direction in the map. Instead, I would like it to work regardless of the direction the car is facing. This is my code I came up with:
function onKeyDown(inputObject, gameProcessedEvent)
if carseat.Position.Y > 2.6 then
if inputObject.KeyCode == Enum.KeyCode.W then
turn.AngularVelocity = Vector3.new(0,0,2000000)
end
if inputObject.KeyCode == Enum.KeyCode.S then
turn.AngularVelocity = Vector3.new(0,0,2000000)
end
end
end
function onKeyUp(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.W then
turn.AngularVelocity = Vector3.new(0,0,0)
end
if inputObject.KeyCode == Enum.KeyCode.S then
turn.AngularVelocity = Vector3.new(0,0,0)
end
end
input.InputBegan:connect(onKeyDown)
input.InputEnded:connect(onKeyUp)
It would be great if you can help me figure out how to solve this. Thanks in advance!!

1 comment
Your approach to the problem has a typical flaw and that is not accounting for how the car is facing. Get the lookvector(what direction its pointing towards) and use that to set the X Y and Z