Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Rotation Along Part's Local Axis?

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

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

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.