Bomb Dropping Problem - Want Bomb to take plane's velocity only on instantiation

Howdy ho everyone! I have a bomb dropping problem that I’m sure is not too difficult to solve but for some reason I just can’t seem to get a working solution.

What I’m trying to do is instantiate a bomb from an airplane and I want the bomb to take the airplane’s velocity but only on the frame that it is instantiated. After the bomb is created I want the physics engine to just take over and make the bomb’s rigid body just basically drop like it would in the real world.

What is happening is that I can get the bomb to instantiate and take, in this case, the plane’s velocity, but the plane’s velocity keeps getting plugged into the bomb’s velocity so when I pull up out of the dive bombing run, the bomb changes direction. Click the link below to see a video example of what I’m talking about.

Bomb dropping problem video explanation

Here’s the relevant code. I’ve basically added to the Aeroplane controller from the Standard assets.
void Update()
{

if (Input.GetKeyDown (KeyCode.LeftShift))
{
DropBomb ();
}
}

public void DropBomb()
{
Vector3 rigidBombVelocity = m_Rigidbody.velocity; //get a new vector3 of the plane’s velocity at time method is run…

Rigidbody newbomb =Instantiate (rigidBomb, rigidBombSpawnPoint.position, rigidBombSpawnPoint.rotation) as Rigidbody; //instantiating the new bom

newbomb.velocity = rigidBombVelocity; //setting the new bomb to have the velocity of the plane when method is run

}

Thanks in advance!

It shouldn’t be inheriting velocity. The code you’ve got should only assign the velocity once.

I thought my code was good but looking at the visuals when playing the bomb motion just looks wrong. I’m going to check what I’m doing again w/a 2nd fixed camera so I can see the bomb relative to the plane and maybe do a debug log to check for the bomb’s velocity.

I’ll be god damned. Once I pulled the camera away from the plane so I could see both the plane and the bomb’s relative motion I realized it is working. I’ve been thinking it hasn’t been working for about the last two weeks and pulling my hair out trying to find a solution! I should have done what instructors tell you when figure drawing…every few minutes stop drawing, stand back and take a look at your drawing from a distance. Then it’s easier to see if something doesn’t look right…

1 Like