Projectile not flying to clicked location

I have a rocket launcher weapon where the rocket intermittently does not fly to the correct position. In some cases, for whatever reason, it flies down and to the left. See the video for illustration.

The projectile has it’s own script, but this is the code that determines the direction:

local position = toolInstance.Handle.CFrame * toolData.weapon.barrelOffset
local direction = (hitPos - position).Unit
part.CFrame = CFrame.new(position, hitPos)
part.Velocity = direction * toolData.weapon.projectile.speed

Now I have added a raycast to this and the result position of the raycast is exactly the same location as the hitPos (clicked location). But when the projectile hits, the impact position is off.

local result = game.Workspace:Raycast(position, direction * 2500, nil)

I do have a vector force that counteracts gravity. It is on the projectile so it’s cloned as well. I know it works because the projectile doesn’t fly into the ground.

Any ideas?

1 Like

I notice in the video the character moves back a bit when the rocket is spawned, consequently I believe the issue is collision, have you set can collide false for the rocket launcher?

I think you’re right. I turned collisions off for the model, but it was for other reasons. Due to the length of the weapon, it was getting hung up on things while the character moved. But it does appear to have been solved. Additionally, I also extended the barrel offset of where the projectile spawns to ensure that the projectile is clear of the weapon when fired.

That brings up another issue that was solved as well. The projectile would rotate wildly when launched. I resorted to adding an AlignOrientation constraint to it to correct the problem. Now it flies dead straight.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.