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!