Finding An Intersecting Point

Alright. So, i have an object, (in this case, a planet), and an asteroid. the asteroid, is heading straight forward, towards the planet. the starting position of the asteroid is random. i need to find an intersecting point, so an explosion appears on the surface of the planet.


Ive tried to do the maths, but im pretty dumb and it doesnt really work :sweat_smile:

How would i get a vector3 from this?
My code :slight_smile: :

	local rndAstroid = astroids:FindFirstChild(sizeString):GetChildren()[math.random(1,#astroids:FindFirstChild(sizeString):GetChildren())]
	local explosion = rndAstroid:Clone()
	explosion.Parent = workspace
	explosion.Material = Enum.Material.SmoothPlastic
	explosion.Color = Color3.fromRGB(255, 136, 38)
	explosion.Name = "Explosion"
	explosion.Transparency = 1

	rndAstroid.ParticleEmitter.Enabled = false
	rndAstroid.Parent = workspace

	rndAstroid.Position = + math.random(-30,30), Planet.Position.Y + Planet.Size.Y * math.random(-5,5), Planet.Position.Z + math.random(-20,20) )

	local planetSurface = + Planet.Size.X / 3.25, Planet.Position.Y + Planet.Size.Y / 3.25, Planet.Position.Z + Planet.Size.Z / 3.25)
	local part ="Part", workspace)
	part.Anchored = true
	part.Size =,.5,.5)
	part.Position = planetSurface 

	local GX = rndAstroid.Position.X - Planet.Position.X
	local GY = rndAstroid.Position.Y - Planet.Position.Y
	local GZ = rndAstroid.Position.z - Planet.Position.Z

	local finalgoal = {}
	finalgoal.Position = Planet.Position
	local tweentime = math.random(3,6)
	local tweenInfoB =

	local tweenB = tweenService:Create(rndAstroid, tweenInfoB, finalgoal)
	task.wait(tweentime / 2.5)
	rndAstroid.ParticleEmitter.Enabled = true

	until rndAstroid.Position == Planet.Position 

	print(tostring(rndAstroid.Position.X),  tostring(Planet.Position.X))

	local finalexplosiongoal = {}
	finalexplosiongoal.Size = * 2,explosion.Size.Y * 2,explosion.Size.Z * 2)
	finalexplosiongoal.Transparency = 1
	local tweenInfoExplosion =
	local explosionTween = tweenService:Create(explosion, tweenInfoExplosion, finalexplosiongoal)

	explosion.Transparency = .5

Thanks for the help

To find the collision point on the surface of the planet from the asteroid (assuming that the asteroid is always heading for the planet’s center) is the asteroid’s position subtract the distance between the two subtract the radius of the planet. I threw together a function for this purpose:

local function GetCollisionPoint(planet, asteroid)
	local distance = (asteroid.Position - planet.Position).Magnitude -- Distance of the asteroid
	local direction = (asteroid.Position - planet.Position).Unit -- Direction of the asteroid relative to the planet's position
	local planet_radius = planet.Size.X / 2 -- Assuming that it is a sphere.
	local asteroid_radius = asteroid.Size.X / 2 -- Assuming that it is a sphere.
	-- The impact position is the asteroid's position subtract
	-- the distance subtract the planet radius times the direction
	local impact_position = asteroid.Position - (, 1, 1) * (direction * (distance - planet_radius)))
	return impact_position

I put this in a script and got this:

Please tell me if I misunderstood the question.

Hope this helps!

1 Like

(Asteroid - YouTube)

Video ^^^

This is interesting as the explosion doesn’t seem to be where the asteroid hit. The planet isnt moving, just the camera. Any ideas why?

ah nevermind, got it working, thanks :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.