Get surface point touched regarding CFrame

I would really love some help here since I suck at math.


What I want to do is a Rocket Launcher, and I had an idea about a knockback.

Really weird summary

Map:
:red_square: for explosion
:black_large_square: the player
:green_square: the point I want to achieve


(Player shoots rocket)


(Rocket explosion misses players)

(Rocket explosion hit player, I want to calculate the green thing)

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?

1 Like

Two methods:

Create and Explosion at the position.

Turn Break Joints in Radius to 0 Percent.

Modify the amount of force you want to push.

Very easy to setup and you can turn off visibility

If you want to apply a force then the Explosion does it automatically alternatively if you want to calculate it yourself

Explosion.Hit:Connect(function(otherPart)
    -- Code if explosion touches part
end)

Alternatively you can use the new Overlap which is workspace:GetPartBoundsInRadius() and then loop over the parts and apply the force that way

You can use either. Explosion is more simpler to do.

1 Like

(For the math is actually pretty easy)

PositionA - PositionB = VectorFromBToBA

1 Like

Mind being more specific?

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.
image
So we want a Vector which points from PointA to PointB? Let’s count what that is.
image
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.

I already knew the basics of basics of Vectors.

I will need to relax a bit, so I can breath, but yes, I am sure I will find a solution.

Useful piece of knowledge.

Thanks

1 Like