Best approach to a "Destructible Objects" System?

Hi all,

I’m attempting to make a “destructible objects” system, similar to those in popular games like Forza Horizon, where you can drive into lampposts/dry-rock walls and destroy/knock them over. However, I’m having a little trouble thinking of both an efficient and effective way of creating this effect.

Currently, I’m just unanchoring the actual “part” (so in my case a lamppost), allowing it to be hit and knocked over and then cloning it so I have a backup. This is all completed within a touch event of a hitbox part, but I know this is quite inefficient, as I’m getting a great deal of delay between the vehicle hitting the hitbox and it actually processing.

I thought that I could just have a relatively fast loop, such as a “while true do” or renderstepped loop, but I thought this might be extremely inefficient, as I’d either have to iterate over all the parts each loop, which is a terrible idea, at least from how I can think of it, or have multiple loops that are detecting for a part in a radius, or using the “GetPartsTouching” event etc.

Although the script doesn’t really contribute to much, as I mainly just need help with figuring out the best method of completing this, here it is anyway:

--> Duplication <--

function dummyClone( subject )
	
	subject.Anchored = false
	subject.CanCollide = true
	
	local replacement = subject:Clone()
	replacement.Parent = subject.Parent
	replacement.Anchored = true
	replacement.CanCollide = false
	
end

--> Hit Detection <--

touched = false

function module.ActivateHitbox( hitbox )
	hitbox.Touched:Connect(function( hit )
		if not touched then
			touched = true
			
			dummyClone(hitbox.Subject.Value)
		end

What’s the most efficient method of doing this? Should I have a bunch of loops on the client that detect this, or allow the server to handle the collision and therefore destruction of parts? I understand entirely that you shouldn’t ask for an entire system to be designed for you, but I’m more just after brainstorms or brief explanations of concepts/methods people have used in the past to effectively achieve this.

Any help is appreciated! :slight_smile:

5 Likes

There are a couple of things I think of after reading this;

I would try moving the destructible objects to the client to minimize the delay caused by the server. Theoretically you could show immediate feedback for the client while you replicate the collision event to other players where their client could then apply that to the corresponding object. Just keep in mind this has a lot of drawbacks or caveats that might make it impractical for your specific case. I would need to test it to see what could be done.

I also think that upon collision you could grab the directional velocity of the car and have the destructible object inherit that velocity after it is unanchored. This could introduce a delay but might prevent the object from completely stopping the car in the time it takes for it to become unanchored. You could also take the mass of the object into account and adjust the velocity of the car and the colliding object accordingly.

Just note that I haven’t really worked on anything like this before because of the problems you mentioned; if anyone has better advice please correct me

6 Likes

this definitely sounds more to the way I imagined it originally, it’s late for me, but I’ll give this a go tomorrow and keep the thread updated! hopefully… lmao

1 Like

It would pay to model the collision properly. Assume momentum is conserved; p (momentum) = mv (mass x velocity). The change of momentum will be the same magnitude for the lamp post and the car (but opposite directions), but since the lamp post has a much lower mass, it will experience a greater increase in velocity then the decrease experienced by the car.

3 Likes

As an update for anyone reading over this, I ended up following a method similar to that described by @SuperBloxxor where I simply detected the touch event via the client and go about the same method of before, cloning it and setting a velocity.

This method doesn’t have much latency from the system I used and it’s pretty effective too as it mimics the hit velocity, allowing the prop to be knocked over/away with quite some decent force

Thanks to those who contributed :slight_smile:

3 Likes