So I have a part for my RayCast and I want to position my bullet holes (that I clone) land where my RayCast part lands (because I have drop for my bullets.) I can not figure out how to do that right now because right now the bullet holes end up where ever my mouse position is when I click it and not where my bullet lands (I know I need a bullethole position for it but I don’t know how to position the bullethole to where the RayCast first hits).
If anyone can help me than that would be awesome.
The position value given by casting a ray is where the ray hit in the world space. You can simpy add the bullet hole there.
Ive tried that it doesn’t work…
I would set the bullet’s CFrame to the newest ray and just offset it by half the length of the ray, that should account for bulletdrop.
Ok I’ll try that but I’m not the smartest about the offset so should I just use Vector3?
yeah CFrame with vector should work
here is a brief example of how I would do it
bullet.CFrame = CFrame.new(ray.CFrame * Vector3.new(0, 0, -ray.Size.Z / 2))
It works but this is whats happening to my bullets: https://gyazo.com/3ca1fce7abe93bf36116351ce901e1bc
(sorry for the loud sounds)
not really sure what’s going on are they interacting with each other? if so try adding them to an ignore and if not could you expand on what’s going on in the gif? Another issue might be the offset would need adjustment for your ray as I subtracted it from the z, maybe you’re sizing your rays with x/y?
Well here’s a video of how it happens: https://gyazo.com/7439d72b8a7d9c4ed4bc74540ff7af9e
I haven’t changed a single thing that you said I think it’s because my bullet is 3 studs long.
I mean even if your bullet is 3 studs long it still sets the CFrame at the endpoint of the ray’s position so the size shouldn’t matter. My guess is that you’re not saving the last ray? If it’s not that then i’m not entirely sure because it should work fine otherwise. If you shoot further away you should try and see where the bullet ends up.
Oh sorry I fixed that problem by doing
BulletHole.CFrame = CFrame.new(BulletHole.Position, BulletHole.Position + RayCast.CFrame * Vector3.new(0, 0, -RayCast.Size.Z / 1.5))
but now the bullets orientation doesn’t end up on the bricks face it always just ends up sideways.
Use the position and normal returned by the raycast.
bulletHole.CFrame = CFrame.new(rayPosition, rayPosition + rayNormal)
that should work depending on which face the bullet hole decal is on
Yes, but this doesn’t take into account of bullet drop.
If you’re using raycasts you use the position and normal of the last raycast. If you’re just launching a part with velocity (which you shouldn’t do imo, just use fast cast or make your own projectile system), you can cast a ray every frame from the part’s old position to it’s new position. If a hit is detected, delete the part and use the position and normal from that.
imo I don’t like the “Normal” thing for the raycast so I just wanna figure it out in my own way without “Normal”
ConcHole.CFrame = CFrame.new(ConcHole.Position, ConcHole.Position + RayCast.CFrame * Vector3.new(0, 0, -RayCast.Size.Z / 1.5))
And the title will explain the rest.
Normal is practically the only way to do this, if you don’t want to do a lot of math, and account for edge case, like slanted corners.
Any reason why you care so much about avoiding the returned normal value? There’s really no sense in trying to figure out the bullet hole’s orientation when the information to do it is handed to you by the API.
Doing it yourself implies figuring out the normal yourself so its not really avoidable.
Raycast is the part I have for the ‘Ray’ and ConcHole is the bullethole I have set for when it hits concrete.