Issues when instantiating moving object from other moving object

I’m making a prototype of a top-down space RPG in which the player can fire weapons from a controllable spaceship - I’ve run into some issues with the projectiles fired though. Namely, if I fire (instantiate) a projectile from the spaceship when it stands still everything works, but if I fire it while the spaceship moves it goes significantly slower than it should and stutters quite a bit.

I move the spaceship by adding a force to a rigidbody of the ship model, and I make the projectile (in this case a laser beam) move by simply changing its forward position every second.

Here’s the code I use, for the spaceship:

//Calculate target position
targetPosition = controlCamera.ScreenToWorldPoint (Input.mousePosition);
			
//Add force in direction
rigidbody.AddForce (targetPosition*shipSpeed*Time.deltaTime;);

And for the projectile:

transform.position = transform.position + transform.forward * speed * Time.deltaTime;

Both in the Update function. I tried using the FixedUpdate function instead for either or both, no difference there.

Any idea why the projectile might be traveling too slow and stutter when fired as the ship moves? It fires straight out from the front of the ship, but significantly faster than the ship’s max speed - yet when firing forward on the move it actually moves way slower than the ship.

well to start with, when dealing with lasers you should be using raycasting and drawline to just draw a quick planar object between you and the targets, lasers act instantly so there easy to emulate.

If you want to deal with projectile well yes you’ll use a rigid body, you’ll make its speed on spawn equal to the current speed of the ship + the base projectile speed.

Thanks for the answers!

This particular laser weapon is not meant to be very realistic - rather a fast traveling projectile as seen in many sci-fi interpretations, so a raycast would not be suitable in this specific scenario.

I’m currently having some issues despite the changes I’ve made though… the projectiles seem to go slower than they should, definitely far slower than the ship no matter if it moves or not. Of course the mass of the projectile works into it too, but I’ll have many different projectiles with different weights, so it might be a bit complicated…

This is my current projectile code (omitting irrelevant parts):

void Start () {
	
speed = speed + GameObject.FindGameObjectWithTag("ship").rigidbody.velocity.magnitude;
		
rigidbody.AddForce(transform.forward * speed* Time.deltaTime);
}