- Home /
Sum of multiple velocities
I have a player object that can shoot a projectile at a velocity of x. When the player starts moving forward, I need the projectile velocity to now be the sum of the player's forward velocity y and the projectile's base velocity of x.
What I currently have is:
projectile.velocity = (projectile.transform.forward + player.transform.forward) * projectileSpeed;
This doesn't seem to work.
How would I do this?
Well what affect is happening? If both are looking down the x axis. Then both forwards would be (0,0,1). so, (0,0,2) * mult.
What's happening right now is the projectile will fly at it's normal speed. Once the player moves forward, any new projectiles will appear to move slower because the player is effectively catching up to it, if that makes sense.
Answer by Razacx · Jul 24, 2014 at 01:07 AM
projectile.velocity = projectile.transform.forward * projectileSpeed + player.rigidbody.velocity;
player.transform.forward is merely a vector that describes how the object is rotated.
Seems to have worked perfectly. $$anonymous$$y thanks!
@charglerode If you are satisfied with the answer and it is correct, then hit the checkmark to accept as the right answer which will gain you and @Razacx karma.