Trying to make a BodyVelocity move based on part rotation and movement variables

I want a BodyVelocity to be set based on movement variables and the direction a part is facing, so the player is able to control it with WASD, arrow keys, joystick, etc. I’m sure there’s a simple solution I’m missing, but this is what I have right now.

player:WaitForChild("BodyVelocity").Velocity = player.CFrame.LookVector * Vector3.new(mh,0,mv) * 10

Original idea:

player:WaitForChild("BodyVelocity").Velocity = (CFrame.new(0,0,0) * CFrame.Angles(0,math.rad(ax),0) * CFrame.new(mh*20,0,-mv*20)).Position
1 Like
Vector3.new(mh,0,mv)

This part does not account for the player’s orientation.
You will have to transform it from world space into object space to make it relative to the player.

player:FindFirstChild("BodyVelocity").Velocity = player.CFrame:VectorToObjectSpace(Vector3.new(mh,0,mv) * 10)
1 Like

It’s working better now, but it has some weird movement now, I’m not sure how to explain it so:

robloxapp-20220601-1124543.wmv (1.7 MB)

(sorry for the download)

Nevermind I fixed it using CFrame:Inverse()