Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

(UPDATE)Bullet is not facing the right direction?

I'm working on a game and there's only one problem: the bullet is facing the wrong direction. This means Holes won't work properly. here]s some details.

Client:

local Start = Weapon.Shoot.CFrame.p
local SD = math.ceil(((Start-Mouse.Hit.p).magnitude/25) + .5)
local SX = math.random(-SD,SD)
local SY = math.random(-SD,SD)
local SZ = math.random(-SD,SD)
local ShotgunDirection = Settings.ShotgunMode and Vector3.new(SX/2.75,SY/2.75,SZ/2.75) or Vector3.new(0,0,0)
local Direction = (Mouse.Hit.p-Weapon.Shoot.CFrame.p + ShotgunDirection).unit
local BulletRay = Ray.new(Start,Direction * Settings.Range)
table.insert(Rays,BulletRay)

Server:

local Distance = (Start-Position).magnitude
local Bullet = Instance.new("Part",workspace.World.DebrisItems)
Bullet.Name = Player.Name.."'s Bullet"
Bullet.Anchored,Bullet.CanCollide = true,false
Bullet.Transparency = .4
Bullet.BrickColor = BrickColor.new("Institutional white")
Bullet.Material = Enum.Material.Neon
Bullet.Size = Vector3.new(.1,.1,2)
	Bullet.CFrame = CFrame.new(Start,Position)
	local Info = TweenInfo.new(Distance/Settings.BulletSpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
	PlayModule:PlayTween(Info,Bullet,{Transparency = 1})
	if Settings.AnimateBullet then
		PlayModule:PlayTween(Info,Bullet,{CFrame = Bullet.CFrame * CFrame.new(0,0,-Distance/2)})
	else
		Bullet.CFrame = Bullet.CFrame * CFrame.new(0,0,-Distance/2)
		Bullet.Size = Vector3.new(.1,.1,Distance)
	end

Photo

2 answers

✓ Accepted answer

It's because the barrel is way close to the part so you need the barrel to move the gun a little bit back. if it didn't work then try making a better ray. Plus it looks like the spawn is not collideable so maybe turn it off

1 comment

0

Oh ok thanks

you have done

Bullet.CFrame = CFrame.new(Start,Position)

let us assume the Position is where the target position. Now, stop tween service, anchor the bullet, see where the bullet is facing. if bullet is facing 90 or 180 degree from the target, that usually mean the bullet's original orientation is not lining up toward the tip direction. you need to add an angle to the CFrame to compensate that.

2 comments

0

How?

0

Tweenservice has nothing to do with that, I already anchored the bullet, and the bullet is facing the weapons barrels direction but it does not work sometimes. And which angle

This discussion is preserved as it was. New answers, comments, and votes are closed.