Problems with fast-moving objects

I’m currently making something like a grenade launcher.
I use RayCast to make explode when a bullet from that grenade launcher landed, and the distance between the ground and the bullet was less than 0.5. I’m trying to make it explode, but due to its high speed, it bounces back to less than 0.5 and explodes on the second fall.
How can I make it explode accurately at the same speed?
Thank you.

2 Likes

Try to make that when it collides with anything he will be anchored, at this point will be locked Near an object/part/model and will explode without bounching

Can you provide your on hit script?

ignore = {}
alreadyexploded = false

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr, mousehitpos)
	alreadyexploded = false
	local Bullet = Instance.new("Part")
	Bullet.Size = Vector3.new(0.5, 0.5, 0.75)
	Bullet.Parent = game.Workspace
	Bullet.Position = script.Parent.BulletGoes.Position
	Bullet.CanCollide = false
	Bullet.Anchored = false
	Bullet.CFrame = CFrame.new(Bullet.Position, mousehitpos)
	Bullet.BrickColor = BrickColor.Black()
	local raychecker = script.Parent.ok:Clone()
	raychecker.Parent = Bullet
	raychecker.Disabled = false
	local velocity = Instance.new("BodyVelocity")
	game:GetService("Debris"):AddItem(velocity,0.1)
	velocity.Parent = Bullet
	velocity.Velocity = Bullet.CFrame.LookVector * 150
	Bullet.Touched:Connect(function(hit)
		if hit.CanCollide == true and not hit.Parent:IsA("Tool") or hit.Parent:FindFirstChild("Humanoid") or not hit.Parent == plr.Character then
			if alreadyexploded == false then
				alreadyexploded = true
				wait(0.01)
				Bullet.Anchored = true
			local positionofexplode = Instance.new("Part")
			game:GetService("Debris"):AddItem(positionofexplode,2)
			positionofexplode.Transparency = 1
			positionofexplode.CanCollide = false
			positionofexplode.Anchored = true
			positionofexplode.CollisionGroupId = 3
			positionofexplode.Size = Vector3.new(0.5,0.5,0.5)
			positionofexplode.Parent = game.Workspace
				positionofexplode.Position = Bullet.Position
				Bullet:Destroy()
			local boom1 = game.ServerStorage.Boom1
			local boom2 = game.ServerStorage.Boom2
			local cloneboom2_1 = boom2:Clone()
			game:GetService("Debris"):AddItem(cloneboom2_1,10)
			cloneboom2_1.Parent = game.Workspace
			cloneboom2_1.Position = Vector3.new(positionofexplode.Position.X + math.random(-4,4), positionofexplode.Position.Y + math.random(0,4), positionofexplode.Position.Z + math.random(-4,4))
			local cloneboom2_2 = boom2:Clone()
			game:GetService("Debris"):AddItem(cloneboom2_2,10)
			cloneboom2_2.Parent = game.Workspace
			cloneboom2_2.Position = Vector3.new(positionofexplode.Position.X + math.random(-4,4), positionofexplode.Position.Y + math.random(0,4), positionofexplode.Position.Z + math.random(-4,4))
			local cloneboom2_3 = boom2:Clone()
			game:GetService("Debris"):AddItem(cloneboom2_3,10)
			cloneboom2_3.Parent = game.Workspace
			cloneboom2_3.Position = Vector3.new(positionofexplode.Position.X + math.random(-4,4), positionofexplode.Position.Y + math.random(0,4), positionofexplode.Position.Z + math.random(-4,4))
			local cloneboom2_4 = boom2:Clone()
			game:GetService("Debris"):AddItem(cloneboom2_4,10)
			cloneboom2_4.Parent = game.Workspace
			cloneboom2_4.Position = Vector3.new(positionofexplode.Position.X + math.random(-4,4), positionofexplode.Position.Y + math.random(0,4), positionofexplode.Position.Z + math.random(-4,4))
			local cloneboom2_5 = boom2:Clone()
			game:GetService("Debris"):AddItem(cloneboom2_5,10)
			cloneboom2_5.Parent = game.Workspace
			cloneboom2_5.Position = Vector3.new(positionofexplode.Position.X + math.random(-4,4), positionofexplode.Position.Y + math.random(0,4), positionofexplode.Position.Z + math.random(-4,4))
			local cloneboom2_6 = boom2:Clone()
			game:GetService("Debris"):AddItem(cloneboom2_6,10)
			cloneboom2_6.Parent = game.Workspace
			cloneboom2_6.Position = Vector3.new(positionofexplode.Position.X + math.random(-4,4), positionofexplode.Position.Y + math.random(0,4), positionofexplode.Position.Z + math.random(-4,4))
			local cloneboom2_7 = boom2:Clone()
			game:GetService("Debris"):AddItem(cloneboom2_7,10)
			cloneboom2_7.Parent = game.Workspace
			cloneboom2_7.Position = Vector3.new(positionofexplode.Position.X + math.random(-4,4), positionofexplode.Position.Y + math.random(0,4), positionofexplode.Position.Z + math.random(-4,4))
			local cloneboom2_8 = boom2:Clone()
			game:GetService("Debris"):AddItem(cloneboom2_8,10)
			cloneboom2_8.Parent = game.Workspace
			cloneboom2_8.Position = Vector3.new(positionofexplode.Position.X + math.random(-4,4), positionofexplode.Position.Y + math.random(0,4), positionofexplode.Position.Z + math.random(-4,4))
			--local explode = Instance.new("Explosion")
			--game:GetService("Debris"):AddItem(explode,2)
			--explode.BlastRadius = 15
			--explode.BlastPressure = 120000
			--explode.DestroyJointRadiusPercent = 0
			--explode.Visible = false
			--explode.Parent = game.Workspace
			--explode.Position = Target.Position
			local cloneboom1 = boom1:Clone()
			game:GetService("Debris"):AddItem(cloneboom1,3)
			cloneboom1.Grenade_explode:Play()
			cloneboom1.Parent = game.Workspace
			cloneboom1.Position = positionofexplode.Position
			local boomcore = game.ServerStorage.Boomed:Clone()
				game:GetService("Debris"):AddItem(boomcore,0.4)
			boomcore.Parent = game.Workspace
			boomcore:SetPrimaryPartCFrame(positionofexplode.CFrame)
			end
		else
			
		end
	end)
end)

I’d say to save the last successful distance and compare it with a new one made on spot. If the old one is smaller than the new one, it means the object has went through the terrain. I would also recommend moving the explosion at the position of the old distance, so the projectile doesn’t explode deep down inside the terrain…

Is there an example script for that explanation?

I just now noticed that you’re using CFrame to move the projectile.

I really don’t recommend this if you want this object to interact with external sources of the world. Most importantly, objects moved with CFrame never detected touch for me in any application I did.
It’s good for doors or basic rotational movement, but not for weapons or vehicles.

I’d recommend BodyMovers for this. RocketPropulsion seems like something that could be used for your bullet.

Thank you for your reply.
It seems to be easy to use, but what I want to make is something like a “grenade launcher”, so I want to add gravity as well. What should I do?

A property of RocketPropulsion is the CartoonFactor. It mentions in the document how the default value is 0.7 to combat gravity. You can try and play around with this value until you get a desired effect.

Well, CFrames is a reliable way to deliver grenades without the inconsistencies of the Physics systems however well math is required. Luckily there is a tutorial for dealing with this like grenades using maths like the tutorial below to draw the bounce curve. Perhaps you can make it so it always explodes on the third bounce as well. Perhaps a raycast along the path of this grenade motion like how fast cast works which in fact fast cast also has physics properties like bounce. Yeah just keep in mind of the alternative options possible.

Thank you for your reply.
It’s a good solution, but it’s hard for me to understand the calculation, so could you explain it in a little more detail?
Thank you.

Sorry for the late reply, gravity is not added even if I change the Cartoon Factor.
What should I do now?