Hello Developers, I’m just wondering on how to make the bullets going at the green lines instead of read lines. What I want to achieve is to make the bullet go at forward direction of where the cannon pointing at but it seems like the bullet keep going straight. Does anyone know how can I fix this? And I also use FastCast module for this.
Script:
local CannonBulletCaster = FastCast.new()
local BulletCastParams = RaycastParams.new()
BulletCastParams.FilterType = Enum.RaycastFilterType.Exclude
BulletCastParams.FilterDescendantsInstances = {Tower, CannonBulletsFolder}
BulletCastParams.IgnoreWater = true
for _, Teammate in Players:GetPlayers() do
if Teammate and Teammate.Team.Name == Tower:GetAttribute('Team') and not table.find(BulletCastParams.FilterDescendantsInstances, Teammate.Character) then
table.insert(BulletCastParams.FilterDescendantsInstances, Teammate.Character)
end
end
for _, BulletPosAttachment in Tower_Root:GetChildren() do
if BulletPosAttachment:IsA('Attachment') and BulletPosAttachment.Name == 'BulletPos' then
local CannonBullet = Instance.new('Part')
CannonBullet.Name = 'CannonBullet'
CannonBullet.Anchored = false
CannonBullet.CanCollide = false
CannonBullet.Color = Color3.fromRGB(0, 0, 0)
CannonBullet.Material = Enum.Material.SmoothPlastic
CannonBullet.Size = BulletSize
CannonBullet.Shape = BulletShapeType
CannonBullet.Parent = workspace
local BulletCasterBehaviour = FastCast.newBehavior()
BulletCasterBehaviour.Acceleration = Vector3.new(0, -5, 0)
BulletCasterBehaviour.AutoIgnoreContainer = false
BulletCasterBehaviour.RaycastParams = BulletCastParams
BulletCasterBehaviour.CosmeticBulletTemplate = CannonBullet
BulletCasterBehaviour.CosmeticBulletContainer = CannonBulletsFolder
local BulletOrigin = BulletPosAttachment.WorldPosition
local BulletDirection = (-BulletPosAttachment.CFrame.LookVector * BulletOrigin).Unit
CannonBulletCaster:Fire(BulletPosAttachment.WorldPosition + -BulletPosAttachment.WorldCFrame.LookVector, BulletDirection, Cannon_AttackRange, BulletCasterBehaviour)
end
end
CannonBulletCaster.LengthChanged:Connect(function(Cast, LastPoint, Direction, Length, Velocity, Bullet)
if Bullet then
Bullet.CFrame = CFrame.lookAt(LastPoint + (Direction * Length), LastPoint)
end
end)
Image: