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

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

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

✓ Accepted answer

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

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