With the above in mind, I want to apply ApplyImpulse on the HumanoidRootPart with minus, so I can push the player the opposite way. How would I do this?
I’m guessing you want to know about Vector math then. The explanation is as simple as it gets.
We usually note Vectors in mathematics in IJK notation. You can substitute them for XYZ.
So let’s say we have a Positional Vector at 2x + 5y. We will be looking at 2d Vectors for simplicity. That will be where our PointA will be. (It will be where the character will be)
Then we have another point. PointB at position 6x + 2y. This will be where our explosion is.
So we want a Vector which points from PointA to PointB? Let’s count what that is.
When we count we can see out Vector from Point A to Point B is going to be -4i + 4j. 4 steps down and 4 steps forward.
Infact we can show this by simply negating vector A from vector B
So, what you need to remember is that PositionA - PositionB = VectorFromBToA
You can apply that to your explosion.
local Explosion = Instance.new("Explosion")
Explosion.Visible = false
Explosion.BlastPressure = 0
Explosion.BlastRadius = 0
Explosion.DestroyJointPercentRadius = 0
Explosion.Hit:Connect(function(part,distance)
if not part.Anchored then
local ImpulseVector = Explosion.Position - part.Position -- The maths
part:ApplyImpulse(ImpulseVector) -- This is where you will put that vector
end
end)
Bear in mind that this code does not account for distance. I am sure you can do that yourself.