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
How would i get a vector3 from this?
My code :
local rndAstroid = astroids:FindFirstChild(sizeString):GetChildren()[math.random(1,#astroids:FindFirstChild(sizeString):GetChildren())]
local explosion = rndAstroid:Clone()
explosion:ClearAllChildren()
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 = Vector3.new(Planet.Position.X + math.random(-30,30), Planet.Position.Y + Planet.Size.Y * math.random(-5,5), Planet.Position.Z + math.random(-20,20) )
local planetSurface = Vector3.new(Planet.Position.X + Planet.Size.X / 3.25, Planet.Position.Y + Planet.Size.Y / 3.25, Planet.Position.Z + Planet.Size.Z / 3.25)
local part = Instance.new("Part", workspace)
part.Anchored = true
part.Size = Vector3.new(.5,.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 = TweenInfo.new(tweentime)
local tweenB = tweenService:Create(rndAstroid, tweenInfoB, finalgoal)
tweenB:Play()
task.wait(tweentime / 2.5)
rndAstroid.ParticleEmitter.Enabled = true
repeat
task.wait()
until rndAstroid.Position == Planet.Position
print(tostring(rndAstroid.Position.X), tostring(Planet.Position.X))
local finalexplosiongoal = {}
finalexplosiongoal.Size = Vector3.new(explosion.Size.X * 2,explosion.Size.Y * 2,explosion.Size.Z * 2)
finalexplosiongoal.Transparency = 1
local tweenInfoExplosion = TweenInfo.new(3)
local explosionTween = tweenService:Create(explosion, tweenInfoExplosion, finalexplosiongoal)
explosion.Transparency = .5
explosionTween:Play()
task.wait(3)
explosion:Destroy()
Thanks for the help