Angles with Vector3

I am trying to make some parts get an impulse using .AssemblyLinearVelocity, but I want them to not go straight forward to the same direction, but have some small random offsets. However, my knowledge on math in general is really bad and I’m not really experienced with Vector3’s in Roblox when it isn’t to position some parts.

This is the piece of the code in which I want to make the offset:

pebble.AssemblyLinearVelocity = Vector3.new(humanoidRootPart.CFrame.LookVector.X * 100, math.random(25, 30), humanoidRootPart.CFrame.LookVector.Z * 100)

I just want to know a way I could make the “pebble” also go to different directions inside 15 degrees. I think this image can describe it better:
image

2 Likes

Try this:

pebble.AssemblyLinearVelocity = Vector3.new(humanoidRootPart.CFrame.LookVector.X * 100 + math.random(0,15), math.random(25, 30), humanoidRootPart.CFrame.LookVector.Z * 100 + math.random(0,15))
1 Like

That worked, thanks. Quite questionable why it worked because I did the same yesterday and the objects got flung away.

Just an addition: using math.random(-15, 15) is the right way, math.random(0, 15) makes the offset just to one side.

pebble.AssemblyLinearVelocity = Vector3.new(humanoidRootPart.CFrame.LookVector.X * 100 + math.random(-15, 15), math.random(25, 30), humanoidRootPart.CFrame.LookVector.Z * 100 + math.random(-15, 15))
1 Like

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