Say I had a loop with a part moving in a specific direction consistently:
while task.wait() do
part.CFrame += part.CFrame.LookVector * .25
end
Increasing the increment of ‘.25’ could also cause hitbox issues, for example if I made the increment ‘2’, there’s a chance that the part would go straight through a player’s model. In that case detection wouldn’t even notice that it passed, and the part would just keep going.
How can I fix this with simple CFraming? I want the projectile to move at a quick speed, but at a small increment so it can be detected.
@puckmans I’ve used LinearVelocity too, seems to work alright. Do you know how I can keep the projectile facing towards the direction it’s going though? I’m not used to the new constraints.
When it’s unanchored it spins around while going in the direction.
-- studs per second
local speed = 5
-- where the bullet will start and the direction it will move to
local cFrame = CFrame.lookAt(Vector3.new(0, 10, 0), Vector3.new(0, 10, -100))
-- create a part
local part = Instance.new("Part")
part.CFrame = cFrame
part.AssemblyLinearVelocity = cFrame.LookVector * speed
part.Parent = game.Workspace
part.Touched:Conect(Function(OtherPart)
part:Destroy()
end)
-- destory part after 30 seconds if it does not hit anything
game.Debris:AddItem(part, 30)
-- add a attachment to the part
local attachment = Instance.new("Attachment")
attachment.Parent = part
-- add vectorForce that will counteract gravity so the bullet moves in a straight path
local vectorForce = Instance.new("VectorForce")
vectorForce.Attachment0 = attachment
vectorForce.RelativeTo = enum.ActuatorRelativeTo.World
vectorForce.Force = Vector3.new(0, game.Workspace.Gravity * part.AssemblyMass, 0)
vectorForce.Parent = part