Get random shrapnel cframes

hi, so basically i’m making an explosion system and the premise is that i want to be able to designate a position and some other settings, but a problem i’m having is making the explosion “fragments” or “shrapnel”. i want them to shoot out at random angles, but i don’t know how to get the cframes for those random angles, (every direction, up, down, left, right, forward, back).

any help is appreciated. thanks.

2 Likes

You could make a LinearVelocity and use math.random() for the directions

1 Like

i’m not using velocity, i’m worried about how to get the directions. and i know how math.random works. thanks for the reply but it’s not what i’m asking about.

You can use math.random() with CFrame.angles() and the origin CFrame.
This should work but I haven’t tried it so I wouldn’t know:

local fragmentCFrame = originCF * CFrame.Angles(math.random()*math.pi*2, math.random()*math.pi*2, math.random()*math.pi*2)
2 Likes

Well, you can just generate a random direction. Then you can take the origin of the explosion and add the direction onto it, with a CFrame.lookat. Then you can just move the shrapnel in the forward direction.

local dir = Vector3.new(math.random(-100,100),math.random(-100,100),math.random(-100,100)).Unit 

local shrapnelCFrame = CFrame.lookat(originPosition, originPosition+dir)

for i = 1,100 do 
wait(.04)
shrapnelCFrame *= Cframe.new(0,0,-.1)
end
1 Like

@ExercitusMortem
@Geolio9

these both work

2 Likes

Give the solution to @Geolio9, don’t give it to yourself, lol

1 Like

Not sure why you gave the solution to yourself instead of the people that helped you?

i was already told once you don’t need to be rude about it. i wasn’t acting selfishly, i originally gave exercitus the suggestion because it was the one that i used, but i knew both would’ve probably worked, so i gave it to a comment that had both mentions. its not like i get money for getting a solution

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.