Bean666 Posted March 24, 2021 Share Posted March 24, 2021 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) end end ) Link to comment
Hydra Posted March 24, 2021 Share Posted March 24, 2021 setElementPosition(localPlayer, x-yourValue, y, z+0.5) ex Link to comment
Moderators Patrick Posted March 24, 2021 Moderators Share Posted March 24, 2021 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) end knockBack(0.5) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now