You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to make ricocheting projectiles
What is the issue? Include screenshots / videos if possible!
When shooting at the floor, it does not bounce, only slides along
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried lots of stuff with the if statement and it seems to be the issue but I don’t know what I can do to fix it
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
if Bullet and Bullet:FindFirstChild("BodyVelocity") then
local StartCFrame = Bullet.CFrame
local Normal = Bullet:FindFirstChild("BodyVelocity").Velocity
local Position = StartCFrame.Position
local RicochetRay = workspace:Raycast(Position, Normal / Properties.MainProperties.Speed)
if RicochetRay and RicochetRay.Instance then
Bullet.BodyVelocity.Velocity = Normal - (2 * Normal:Dot(RicochetRay.Normal) * RicochetRay.Normal)
return true
end
return false
end
Hey! So the first thing I noticed is that you are using body velocity inside your script. Body Velocity has been deprecated, this means roblox does not advise the support of using Body Velocity. Yes you can still use it but you should not, its buggy and will most likely cause issues later on. Instead you should use Linear Velocity, linear velocity is the new and improved Body Velocity.
Now for your main question, I suggest changing the elasticity in CustomPhysicalProperties to make your projectile ricochet. The link to both CustomPhysicalProperties and Linear Velocity is down below. Let me know if you have anymore questions! Happy programming
What happens if you make the Density of the Part very low, or even Massless?
Gravity is going to affect Parts, so if you shoot it towards the ground it’s always going to want to drop.
I am now using linear velocity but the elasticity doesn’t make it bounce off walls, and the original formula didn’t work, also i tried making it massless before putting this up but it didnt work
Based on the video, the problem seems to only happen when the angle between the velocity and the horizontal surface is low. The lower that angle is, the longer the raycast needs to be to hit the surface. So I believe the issue is that the raycast doesn’t hit the surface so the part keeps trying to move in the same direction but the surface prevents downward movement and, as a result, the part moves horizontally.
I would suggest using a shapecast or multiple raycasts in different directions.