Need help pushing character away from something properly

Ok so I have two issues with my game involving pushing players.

Issue 1: When a player gets ragdolled they get pushed away from the person who hits them.
the direction is determined by the lookvector of the humanoidrootpart of the person who hits them.
this is an issue because if I hit someone then turn around they will get pulled towards me as they get ragdolled rather than pushed away. How can I make it so the victim of the attack ALWAYS gets pushed away no matter where the attacker is facing?

Issue 2: I reverted an update where hitting players slightly pushes them back due to a problem.
I did the same thing where it got the lookvector of the attacker and the same issue occured as ragdoll however there was also ANOTHER issue.
image
dont mind the poor drawing but the red is the attacker and the blue is the person getting hit. the black line is where the attacker is facing. if the black line is even slightly off center the person hit gets pushed back + to the side a little bit which is a problem. I want it to be a direct push straight rather than sideways. (the green line indicates where the victim would get pushed as the black line is slightly off-center, and I obviously dont expect people to attack on-center perfectly)

All help is greatly appreciated! Should be a simple problem to fix.

Also I use bodyvelocities to push them.
forgot to mention that

I think you might be looking for this special function.

https://developer.roblox.com/en-us/api-reference/function/BasePart/ApplyImpulse

For getting the direction from object A to B you can simply do

(B.Position - A.Position).Unit

then multiply by whatever force you want for example 10. Then just pass the force into the function and it should work.

2 Likes

I just tried this and for some reason apply impulse doesn’t work on the humanoidrootpart.
The code was something like this.

char.humanoidrootpart:ApplyImpulse:((char.humanoidrootpart.positon - victim.humanoidrootpart.positon).Unit*number)

obviously without the lack of caps lock thats just a rough retype

Why does it not work? Do you know why?

You can use what @koziahss posted to get a vector facing the hit player’s character from the attacker, however for the number you multiply the unit vector by it needs to be in the thousands for the character to be nudged.

3 Likes

ah that makes much more sense, thank you for clarifying! :smiley: