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.