Imagine a car, that was driven off a bridge and drop to the ground and can either explode/break its car parts. However, the falling speed can be different. If it’s slow, then I want it not to explode. Otherwise, I want it to explode/break its part. What things should I know to create this concept?
Velocity, If statements, Welds. Probably CFrame operations.
1. if statements, velocity.magnitude for e.g. if body or some part in car model.velocity.magnitude > some speed then
2. Change the material to for example corroded metal.
3. If your car is made out of many parts then, remove welds.
4. Play a sound when it explodes. How to detect it? Simply check if one of the part’s material equals corroded metal.
What does Velocity do in this case?
Velocity is the property of a part that explains how fast a BasePart is moving in each x,y,z axis.
You need some sort of damage detector. As far as your thresholds, I’d suggest printing out the values and making notes of acceptable heights(to you) and what numbers they produce then you can set up your if statements accordingly.
There are lots of threads on how to do damage detection based on velocities here are a couple:
and
So you’re saying that if an unanchored part is falling, it has Velocity?
Can you explain to me what is a damage detector?
A server side script that clears up the debris after the car has exploded and sent a remoteevent. Will also need some raycasting to detect if the car is in the air or not and if the distance of the ray is bigger than how many studs you want the car to explode at then you can make the Explode function run if it is lets ray blow 25 studs then the car does not explode.
I made something to maybe help you a little ting to help you don’t use this as your actual code just use it to understand what you have to do:
Code:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Vehicles = workspace.Vehicles
function GetHeightPart(Part, RayNewY)
local RayNew = Ray.new(Part.Position, Vector3.new(0, RayNewY, 0))
local Part2, Position, SurfaceNormal, Material = workspace:FindPartOnRay(RayNew)
if Part2 then
local Magnitude = (RayNew.Origin - Position).Magnitude
return Magnitude
end
end
function LocateLocalPlayerVehicle()
local LocalPlayerVehicle = nil
for Number, Instance2 in pairs(Vehicles:GetChildren()) do
local Owner = Instance2:FindFirstChild("Player").Value
if Owner == LocalPlayer.Name then
LocalPlayerVehicle = Instance2
end
end
return LocalPlayerVehicle
end
function ExplodeVehicle(Name)
local LocalPlayerVehicle = LocateLocalPlayerVehicle()
if LocalPlayerVehicle then
print("Exploded")
end
end
local ForceExplodeOn = workspace.Part
local MaxVelocity = 50
RunService.RenderStepped:Connect(function()
if GetHeightPart(ForceExplodeOn, -100) > 25 and ForceExplodeOn.Velocity.Magnitude > 50 then
ExplodeVehicle(LocalPlayer.Name)
end
end)
I have some questions.
- Why did you set the ray’s Y axis to -100?
- What does the ForceExplodeOn part mean?
That’s how far you want the Ray to cast to. So if your game has very high places that your car can drive off you might want to set it to -1000000 but if not set it to 10000.
It just of far down the ray shoots.
Visual Interp:
-10
|
|
|
|
|
|
|
|
|
|
\ /
Thats just the name of a variable of the part you want to explode you can name it whatever you want like PartToExplode = workspace.Vehicle.Chassis
What if my car is a model full of unanchored pads and are using weld constraints? Also I still don’t understand the positive and negative integer of the Y axis.
Use the ray with ignore list and cast the ray down from the chassis with all other parts of the model in the ignore list