You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to make the bullets come out of the guns(characters holding) to be the same as the viewmodels. Note: I still didnt add the bullets come out from character because Im not sure how to exactly do it as I said.)
What is the issue? Include screenshots / videos if possible!
What solutions have you tried so far? I couldnt find anything because I didnt know how to corretly search about 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!
You’ll add an attachment near the front of the barrel. The bullet’s CFrame will then be aligned with the attachment’s CFrame. From there, you can apply an impulse to the bullet in the direction of its lookvector
local module = {}
local DamageEvent = game:GetService("ReplicatedStorage").Events.BulletDamage
function module(player, gun, endposition)
local gunConfig = require(gun.Config)
local BulletVelocity = gunConfig.bulletVelocity
local BulletDamage = gunConfig.bulletDamage
local Barrel = gun.Barrel
local Bullet = Instance.new("Part")
Bullet.Size = Vector3.new(0.2,0.2,0.5)
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Color = Color3.new(1, 0.92549, 0.0980392)
Bullet.Material = Enum.Material.Neon
Bullet.Parent = game.Workspace
Bullet.CFrame = CFrame.new(Barrel.Position, endposition)
local Loop
Loop = game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
local Hit = workspace:Raycast(Bullet.Position, Bullet.CFrame.LookVector * BulletVelocity * 1.5)
if Hit then
if Hit.Instance.Parent:FindFirstChild("Humanoid") and DamageEvent ~= nil and Hit.Instance.Parent.Name ~= player.Name then
DamageEvent:FireServer(Hit.Instance.Parent, BulletDamage)
Loop:Disconnect()
Bullet:Destroy()
else
Loop:Disconnect()
Bullet:Destroy()
end
end
Bullet.CFrame *= CFrame.new(0, 0, -BulletVelocity * (deltaTime * 60))
end)
end
return module
client side on viewmodel. (İt gives damage on the server but rn it doesnt matter). I want the gun on the character to be aligned with the bullet with viewmodels bullet. How do I make them shoot the same bullet on the same position?
local module = {}
local DamageEvent = game:GetService("ReplicatedStorage").Events.BulletDamage
function module(player, gun, endposition)
local gunConfig = require(gun.Config)
local BulletVelocity = gunConfig.bulletVelocity
local BulletDamage = gunConfig.bulletDamage
local Barrel = gun.Barrel
local Bullet = Instance.new("Part")
Bullet.Size = Vector3.new(0.2,0.2,0.5)
Bullet.Anchored = false
Bullet.CanCollide = false
Bullet.Color = Color3.new(1, 0.92549, 0.0980392)
Bullet.Material = Enum.Material.Neon
Bullet.Parent = game.Workspace
Bullet.CFrame = Barrel.CFrame
local Loop
Loop = game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
local Hit = workspace:Raycast(Bullet.Position, Bullet.CFrame.LookVector * BulletVelocity * 1.5)
if Hit then
if Hit.Instance.Parent:FindFirstChild("Humanoid") and DamageEvent ~= nil and Hit.Instance.Parent.Name ~= player.Name then
DamageEvent:FireServer(Hit.Instance.Parent, BulletDamage)
Loop:Disconnect()
Bullet:Destroy()
else
Loop:Disconnect()
Bullet:Destroy()
end
end
Bullet:ApplyImpulse(Barrel.CFrame.LookVector * 100) -- * gunConfig.bulletVelocity?
end)
end
return module
Think like both are holding(animated) and when I shoot(bullet goes out from viewmodel and the bullet goes out from the marked area) the bullet is not aligned with the characters guns barrel(I marked on the blue)