-
What do you want to achieve? Keep it simple and clear!
How can I make C4 that you can throw and then when the C4 hits and object it sticks to it and its orientation is the same as the object it hit, and then theres a gui on your screen where you can blow the C4 up. -
What is the issue? Include screenshots / videos if possible!
I dont know how to make the C4 stick to objects and then its orientation is the same as the object its on. I know how to make an explode gui though. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried Devfourm and YouTube.
Look up Raycasting in the create.roblox.com site.
You’ll see that the raycast result returns the Normal of the part the ray hits.
You can use this orientation to CFrame your C4.
Here’s a post with a similar issue and solution.
To make the C4 stick to objects and have its orientation match the object it hit, you can use a combination of raycasting and attachments.
Here’s an example implementation:
- Create a C4 model with a Part called “Explosive” and a ClickDetector to trigger the explosion.
- Add a BodyVelocity and BodyAngularVelocity to the Explosive Part so that it moves in the direction it was thrown and rotates in the air.
- In the ClickDetector’s OnClick event, add the following code to start the explosion:
local attachment = game:GetService("Workspace").C4Attachment:Clone()
attachment.Parent = explosivePart
attachment.CFrame = explosivePart.CFrame
This code clones a pre-made Attachment object from the Workspace and attaches it to the Explosive Part. It then sets the Attachment’s CFrame to match the Explosive Part’s CFrame, so that the Attachment is in the same position and orientation as the Explosive Part.
- In a loop, use raycasting to detect when the C4 hits an object. When it does, create a new Attachment and set its CFrame to match the hit Part’s CFrame:
while true do
if explosivePart.Velocity.magnitude == 0 then
local hitPart, hitPosition, hitNormal = workspace:FindPartOnRay(Ray.new(explosivePart.Position, explosivePart.CFrame.LookVector * 100))
if hitPart then
local attachment = game:GetService("Workspace").C4Attachment:Clone()
attachment.Parent = hitPart
attachment.CFrame = CFrame.new(hitPosition) * hitPart.CFrame:Inverse()
break
end
end
wait()
end
This code checks whether the Explosive Part’s velocity is zero (i.e. it has hit an object). If it has, it casts a Ray in the direction the Explosive Part was thrown and uses FindPartOnRay to detect the hit Part.
If a hit Part is found, the code creates a new Attachment, sets its Parent to the hit Part, and sets its CFrame to match the hit Part’s CFrame at the hitPosition.
Note that this is just one possible implementation and you may need to adjust it based on your specific needs. Also, be sure to handle edge cases such as the C4 hitting the ground or missing all objects.
Hey bro this is still written by chatgpt