Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a bullet hole effect for my Gun System?

Asked by
SnowieDev 171
4 years ago
Edited 4 years ago

Hello, I'm currently making my own gun system for my zombie game. I'm having issues making the bullet holes for extra effects. When they're spawned in they don't face the right way I wanted them to face. I think its about how I raycasted but I'm not really sure.

How I wanted the bullet hole to look/face: https://prnt.sc/t585i5

How it actually looks/faces like: https://prnt.sc/t586qh

Extra Info: The line of code is in a localscript; I'm using a remote event to fire the bullet.

The code below is possibly incredibly unorganized on your screen, so I recommend using the "View Source" window to observe it.

01local NewRay
02local ProjectileHitPosition
03if not Aiming then
04    local SpreadCalculator = Vector3.new(FirePoint.WorldCFrame.Position.X + math.random(-Configuration.Spread, Configuration.Spread)/1000, FirePoint.WorldCFrame.Position.Y + math.random(-Configuration.Spread, Configuration.Spread)/1000, FirePoint.WorldCFrame.Position.Z + math.random(-Configuration.Spread, Configuration.Spread)/1000)
05    local NewRay2 = Ray.new(FirePoint.WorldCFrame.Position, (Mouse.Hit.Position - SpreadCalculator).Unit * Configuration.Range)
06    ProjectileHitPosition = (Mouse.Hit.Position - SpreadCalculator).Unit * Configuration.Range
07    NewRay = Ray.new(NewRay2.Origin, CFrame.Angles(math.rad(math.random(-Configuration.Spread, Configuration.Spread)), math.rad(math.random(-Configuration.Spread, Configuration.Spread)), math.rad(math.random(-Configuration.Spread, Configuration.Spread))) * NewRay2.Direction)
08elseif Aiming and Configuration.Sniper then
09    local SpreadCalculator = Vector3.new(FirePoint.WorldCFrame.Position.X + math.random(-Configuration.SniperSpread, Configuration.SniperSpread)/1000, FirePoint.WorldCFrame.Position.Y + math.random(-Configuration.SniperSpread, Configuration.SniperSpread)/1000, FirePoint.WorldCFrame.Position.Z + math.random(-Configuration.SniperSpread, Configuration.SniperSpread)/1000)
10    local NewRay2 = Ray.new(FirePoint.WorldCFrame.Position, (Mouse.Hit.Position - SpreadCalculator).Unit * Configuration.Range)
11    ProjectileHitPosition = (Mouse.Hit.Position - SpreadCalculator).Unit * Configuration.Range
12    NewRay = Ray.new(NewRay2.Origin, CFrame.Angles(math.rad(math.random(-Configuration.SniperSpread, Configuration.SniperSpread)), math.rad(math.random(-Configuration.SniperSpread, Configuration.SniperSpread)), math.rad(math.random(-Configuration.SniperSpread, Configuration.SniperSpread))) * NewRay2.Direction)
13elseif Aiming and not Configuration.Sniper then
14    local SpreadCalculator = Vector3.new(FirePoint.WorldCFrame.Position.X + math.random(-Configuration.IronsightSpread, Configuration.IronsightSpread)/1000, FirePoint.WorldCFrame.Position.Y + math.random(-Configuration.IronsightSpread, Configuration.IronsightSpread)/1000, FirePoint.WorldCFrame.Position.Z + math.random(-Configuration.IronsightSpread, Configuration.IronsightSpread)/1000)
15    local NewRay2 = Ray.new(FirePoint.WorldCFrame.Position, (Mouse.Hit.Position - SpreadCalculator).Unit * Configuration.Range)
View all 44 lines...
0
Could you post an image of what direction the bullet holes face? Benbebop 1049 — 4y
0
Yeah sure SnowieDev 171 — 4y

1 answer

Log in to vote
1
Answered by
SteamG00B 1633 Moderation Voter
4 years ago

There is a lot going on there, but thankfully, all you need is the CFrame to place the part that the decal is on, and by using the normal you got from the FindPartOnRay, you can get the exact position and rotation that the decal part needs to be.

1CFrame.new(HitPosition)*CFrame.Angles(math.rad(Normal.X),math.rad(Normal.Y),math.rad(Normal.Z))

Also, if for whatever reason, the decal is facing the wrong way, all you would need to do is rotate it again by multiplying by another CFrame.Angles:

1CFrame.new(HitPosition)*CFrame.Angles(math.rad(Normal.X),math.rad(Normal.Y),math.rad(Normal.Z))*CFrame.Angles(0,math.rad(180),0)

The reason yours didn't work is because CFrame.new(HitPosition, HitPosition + Normal) means that it is positioned at HitPosition, but it is facing the point at HitPosition + the normal, when all you want it to do is face in the direction of the normal alone.

0
Sorry, but it still has the same result. Thanks for attempting to help me. SnowieDev 171 — 4y
0
Hold on, I think I know the problem. The part is facing the right way, it's just that you have the decal on the top rather than the side facing away from the hit part. SteamG00B 1633 — 4y
0
So you can either rotate it by multiplying by a CFrame.Angles() or you can put the decal on the side facing away from the hit part. SteamG00B 1633 — 4y
0
Thanks! SnowieDev 171 — 4y
Ad

Answer this question