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

'Pushing' a player when hit by projectile relative to the projectile's direction?

Asked by 6 years ago

I'm looking for a way in which a player, when hit by a projectile, is flung backwards and in the direction of the projectile that hit them.

Currently - when hit by the projectile - the player's torso's velocity is simply set to the lookVector property of the projectile and multiplied, like so:

projectile.Touched:connect(function(part)
    local hum = projectile.Parent:FindFirstChild("Humanoid")
    if humanoid then
        hum.Parent.Torso.Velocity = (projectile.CFrame.lookVector) * 100
    end
end

However, what I'm trying to do is to apply some sort of upwards force on the player, so they are properly flung backwards rather than at the ground. This Gyazo image better demonstrates what I'm trying to achive.

If anyone could give me a point in the right direction here, I'd be very grateful.

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

You want them to fly up? Sure.

projectile.Touched:connect(function(part)
    local hum = projectile.Parent:FindFirstChild("Humanoid")
    if humanoid then
        hum.Parent.Torso.Velocity = Vector3.new(0,100,0) + (projectile.CFrame.lookVector * 100)
    end
end
Ad

Answer this question