I don’t know of any question that ask about adding multiple velocities to an object, but this might come in handy for a few game ideas if deciding to use it.
I am making a game project that involves the player shooting bullets from a rotating unit in a fast-moving car. The gist is that in addition to the bullets moving from the direction of the unit and its own speed, they should also move based on the velocity of the player. However, when trying out the implementation, it does not work as expected.
I will show you the following “velocities” added together to the bullet
Player Driver - The desired velocity from the driver object to be added to the bullet
rb2d.velocity = tsfm.up * speedCurr; // used to get velocity of driver in current frame, including rotation
Bullet - Velocity of the bullet applied by default
m_transformCache.position += m_transformCache.up * m_speed * deltaTime; // another way to update velocity
Component to add driver’s velocity to the existing bullet gameObject:
// snapped velocity is retrieved from driver.tsfm.up * speedCurr // //gameObject.transform.Translate(m_snappedVelocity * Time.deltaTime); gameObject.transform.position += m_snappedVelocity * Time.deltaTime;
However, none of the previous solutions worked since the driver’s velocity somehow screws up the vector when entering into opposing values.
Is there a way that I can add the two global velocity vectors based on a local object’s direction vector so that the bullets can move with the player’s velocity like bullets moving straight with a scrolling background? I would be very thankful if someone can give a clear answer to adding multiple velocities to any object like bullets.