Jump to content

Knockback effect?

Recommended Posts

Hi i'm trying to do a knockback effect, but instead idk how to calculate player's position, all i can do is to set him flying upwards which I want backwards, i want him to be thrown backwards wherever he's facing, like if he's facing north he will be knocked south, if im facing west i will be knocked east, how do I do that?


addEventHandler( "onClientRender",root,
	function( )
		local flying = getElementData(localPlayer, "knockback") 
		local x, y, z = getElementPosition(localPlayer)
		if knockback then 
			setElementPosition(localPlayer, x, y, z+0.5)



Link to post
  • Moderators
function knockBack(distance)
    local x, y, z = getElementPosition(localPlayer)
    local _, _, r = getElementRotation(localPlayer)
    local angle   = math.rad(r - 90)
    distance      = distance or 1
    x             = x + math.cos(angle) * distance
    y             = y + math.sin(angle) * distance
    setElementPosition(localPlayer, x, y, z)



Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...