GunHandler.cast = function(gun, endPos: Vector3, force)
local BulletSpawn = gun.BulletSpawn
local Bullet = RepStorage.Bullets:FindFirstChild("Bullet"):Clone()
local spawnPos = BulletSpawn.Position
local direction = (endPos - spawnPos).Unit
local forward = BulletSpawn.CFrame.LookVector
-- is bullet pointing backwards
if direction:Dot(forward) < 0 then
direction = forward
end
Bullet.CFrame = CFrame.new(spawnPos, spawnPos + direction)
Bullet.Parent = workspace.Bullets
Bullets[Bullet] = {
TimeElapsed = 0,
StartPos = Bullet.Position,
Gun = gun,
Force = force,
EndPos = spawnPos + direction * 1000,
DespawnTime = 4
}
end
``` (endpos is mouse.hit)
so the bullet spawns at the tip of the guns barrel but sometimes the gun goes inside a wall or something and the barrel becomes IN FRONT of mouse.hit causing the bullet to go backwards, how do i fix this? the dot doesnt work
#help with bullet going backwards
1 messages · Page 1 of 1 (latest)
remove the if statement if direction:Dot(forward) < 0 then direction = forward end and reverse the lookvector or reverse the spawner object since your spawner object is most likely facing backwards
you can add a decal on the front of your spawner object if you need to see it
ill try that and get back to u thanks
im assuming its not an issue with your calculations since i didnt fully read them, if that doesnt work ill look at your calculationsa bit more
it didnt work
wait did u understand my question
the bullet shoots fine except that when the gun goes inside a wall or inside the floor
ohhhh
just raycast then
or wait
what
oh you fixed it?
yes