antfarmar / Unity-3D-Asteroids

A simple Asteroids clone. In 3D.
The Unlicense
65 stars 15 forks source link

Bullets Could Inherit Ship's Velocity #35

Closed antfarmar closed 8 years ago

antfarmar commented 8 years ago
Problem
ghost commented 8 years ago

https://github.com/antfarmar/Unity-3D-Asteroids/blob/b9c0cbda61f6442a558a2b94945409720f054d78/Assets/Asteroids/Scripts/MicroBehaviours/ShipShooter.cs#L88-L93

Add the velocity of the rigidbody to the bullet. And get rid of those comments I placed there while you are at it :)

Bullet().Fire(nozzle.position, nozzle.rotation, direction * velocity + rb.velocity);
antfarmar commented 8 years ago

Oh yeah, vector addition. Who knew rigidbodies had a velocity property? :laughing: I also renamed the variables to distinguish scalars from vectors.

Commit a56a4ed

void FireBullet(Vector3 direction, float speedScalar = bulletSpeed)
{
        direction = (direction * speedScalar) + rbody.velocity;
        Bullet().Fire(nozzle.position, nozzle.rotation, direction);
}

Could probably also just collapse those 2 parameters to simply velocity and have the caller do the math.