What kind of methods are there to making a fireball explode when it impacts with a building or tree etc just anything on the map. I’m aware of a good amount of methods but it would be nice to know how much people know so that I can get some more insight on what the most efficient way to do this would be.
There are a Couple:
Magnitude
if an Object gets within a certain Range of an Instance, it will explode
Example:
local Mag = (Part.Position - Instance.Position).Magnitude
if Mag < 7 then
-- Explosion code
end
TweenService
You can make the Fireball Tween towards a certain Position and when the Tween is finished, Explode
Example:
local TS = game.TweenService
Tween = TS:Create(Part, TweenInfo.new(1), {Position = pos})
Tween:Play()
Tween.Completed:connect(function()
-- Explosion code here
end)
Mouse
(RemoteEvent
Recommended)
Have the Fireball follow the Mouse Position, when It does, explode
Mouse.Hit.p
is a good Example
Part.Position = Mouse.Hit.p
TweenService
can be used here
Touched
(Not Very Efficient)
When the Fireball Touches something, it will Explode
Part.Touched:Connect(function(hit)
-- Explosion code
end)
CFrame / Vector3
(Ugly)
Set the Position of the Fireball
Part.CFrame = YourPos.CFrame
Part.Position = YourPos
Alternative for TweenService
is CFrame:Lerp()
Technically already said here, but yeah. That’s one way
Raycasting wasn’t mentioned in any form in your reply. I will say that raycasting is the best way to do it.
here’s some cool example code that i slapped together. do not use this in your project. it does not replicate to other clients.
local mouse = game.Players.LocalPlayer:GetMouse()
local proto = game.ReplicatedStorage:WaitForChild('prototype')
local speed = 4.5
local hb = game:GetService('RunService').Heartbeat
mouse.Button1Down:connect(function()
local hitpos = mouse.Hit.p
local p = proto:Clone()
local origin = game.Players.LocalPlayer.Character.HumanoidRootPart.Position + Vector3.new(0, 2.5, 0)
local dir = (hitpos - origin).unit
p.Position = origin
p.Parent = workspace
while true do
if (p.Position - hitpos).magnitude < speed then
break
end
p.CFrame = p.CFrame:lerp(CFrame.new(p.Position + dir*speed, hitpos), 0.5)
local rc = RaycastParams.new()
rc.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
local raycastResult = workspace:Raycast(p.Position, dir*speed, rc)
if raycastResult then
break
end
hb:wait()
end
local explosion = Instance.new('Explosion')
explosion.BlastPressure = 0
explosion.Position = p.Position
explosion.Parent = workspace
game.Debris:AddItem(explosion, 5)
p:Destroy()
end)
Not sure if you read, but i said Technically, doesnt mean it is
Yeah. Im pretty sure i read your post. You did not technically say it as you only talked about using the mouse position. You did not mention using raycasts one time.
The simplest would be to use .Touched.
local part = script.Parent -- The fireball
part.Touched:Connect(function(otherPart)
-- Create a new explosion
local ex = Instance.new('Explosion')
ex.Position = part.Position
ex.Parent = part
-- Then, destroy the part
part:Destroy()
end)
Please do not use Touched. It is not very reliable and is quite old.
I say it would be most efficient if you use raycasting!!
Raycasting also isnt very efficent, yes it may be great with Certain things, but with objects attempting to follow it, its can be very inconsistent
Where did you hear this? Raycasts are very efficient as long as you are not spamming hundreds of long raycasts every frame. Raycasts are very consistent.
Experience, Creating a Raycast itself IS efficient, but with Parts, it CAN be Inconsistent
Im not an idiot
If you have anything more to say, send a personal Message, i would not want to flood this post with stupid crap like this
Raycasting / Region3 seems like the best way to make an impact happen once a ball collides with terrain. Whenever I try this though there’s an occasion where the ball will sometimes ignore the collision which I can only assume has to do with how fast the balls moving as well as how many checks p/s
Just because it’s old doesn’t mean it doesn’t work. Roblox hasn’t deprecated it yet, and it’s widely used in many games.
Touched is the most easy, and concise way of doing this.
No it is not. Matter of fact it is the worst performance and precision wise. Raycasts are infinitely better for MOVING PROJECTILES. for stationary/static objects touched would be the best option
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.