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

How do I make the player dodge to the right?

Asked by
fdfxd 50
9 years ago

This is my attempt using body velocity. in first person. It does dodge but not to the right, just a random direction.

--Developed by Cluster studios, FDFXD
--Dodge Right using E, UT 2004 style

repeat wait() until game.Players.LocalPlayer.Character
player = game.Players.LocalPlayer.Character:WaitForChild("Torso")

debounce = false

function DodgeRight()
    if debounce == false
        then debounce = true
        end
    if script.Parent.Parent.powers.Mana.Value >25
        then
        script.Parent.Parent.powers.Mana.Value = script.Parent.Parent.powers.Mana.Value - 25
    Instance.new("BodyVelocity",player)
    player.BodyVelocity.Name = "Dodge"
    player.Dodge.velocity = Vector3.new(600,0,0)
    player.Dodge.maxForce = Vector3.new(140000,0,0)
    wait(1)
    player.Dodge:Destroy()
    debounce = false
end
end

function onKeyPress(inputObject, gameProcessedEvent)-- This is what filters the Keystroke
    if inputObject.KeyCode == Enum.KeyCode.Q then
        DodgeRight()
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress) -- This is what outputs the keystroke

1 answer

Log in to vote
0
Answered by 9 years ago

The problem is that you're having the player always dodge towards the positive X axis (which is independent of where the player is looking or what direction their character is facing).

You need to use CFrame.Angles(0, -math.pi/2, 0) * lookVector (replacing lookVector with either the character's Torso's CFrame's lookVector, or else the lookVector of their camera) to get the velocity to use. (Also consider taking the 'y' component out of the lookVector and then re-normalizing it so that if their torso is angled sideways, they won't fly up/down at all). For dodging left, just take out the minus sign before the 'math.pi/2' part. (math.pi/2 is 90 degrees.)

Ad

Answer this question