Ad
Log in to vote
0

VectorForce not canceling out when I move?

Asked by
WH_HAN 2
3 days ago

Hello! I am currently making a fly script and it works fine but whenever I move forward, my character doesn’t stop and continues to keep moving.

What do you want to achieve? I would like for my character to slowly come to a stop whenever I let go of the key.

What solutions have you tried so far? I’ve tried creating an opposite force to counteract the original force, But that just made me go the other way and my character still wouldn’t stop.

Here is my current code:

local FORWARD_KEY = Enum.KeyCode.W

local function onMove1(actionName, inputState)
    if inputState == Enum.UserInputState.Begin then
        -- If the player presses down the button then they move forward
        player.Character.HumanoidRootPart.VectorForce.Force = Vector3.new(0,48,0)
    elseif inputState == Enum.UserInputState.End then
        -- when the player releases the button then they are supposed to stop moving 
        player.Character.HumanoidRootPart.VectorForce.Force = Vector3.new(0,0,0)
    end
end

ContextActionService:BindAction("Move1", onMove1, false, FORWARD_KEY)

If anyone can help me, That would be greatly appreciated!

Answer this question