Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Rotation Along Part's Local Axis?

Asked by 7 years ago

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!!

0
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 lukeb50 631 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

turn.AngularVelocity = carnose.CFrame.lookVector * 2000000

rightVector is it's local X axis upVector is it's local Y Axis lookVector is it's local Z axis

Ad

Answer this question