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

Body Velocity sideways?

This script makes a BodyVelocity and send the the user backwards. I want to make it to the same but to the right.

How would I do this? This is the script:

local EvasionForce = Instance.new("BodyVelocity", Player.Character.HumanoidRootPart)
EvasionForce.maxForce = Vector3.new(math.huge, math.huge, math.huge)
EvasionForce.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * - 100

1 answer

✓ Accepted answer

There's a neat trick involving using vectorToWorldSpace to get a specific axis of a CFrame. For example, doing CFrame:vectorToWorldSpace( Vector3.new(0,1,0) ) gets the "upwards" lookVector of a CFrame, whileCFrame:vectorToWorldSpace( Vector3.new(1,0,0) ) gets the "rightwards" lookVector of a CFrame.

Counterintuitively, CFrame:vectorToWorldSpace( Vector3.new(0,0,-1) ) get's the "front" lookVector of the CFrame, but you're better of just getting the .lookVector property in that case (the image on this page explains this quirk a bit).

Anyway, for your problem, all you need to do is substitute

Player.Character.HumanoidRootPart.CFrame.lookVector

with

Player.Character.HumanoidRootPart.CFrame:vectorToWorldSpace( Vector3.new(1,0,0))

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