x


Adding Momentum to Missiles

Okay so I have a space ship thats firing missiles. I am using Ridgidbody.AddForce to control the ship.

When I fire a projectile I want to add the speed (or momentum) of my ship to the missile, otherwise the faster I travel the missile leaves my ship and either I crash into it, or it trails behind me.

Any ideas?

The projectile has a Force variable that applies an AddForce to it once it enters the scene.

more ▼

asked Mar 15 '11 at 07:11 PM

mike 5 gravatar image

mike 5
2 2 2 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You could set the velocity of the missile the same as on your ship, then apply impulse force in the direction you want to shoot it at to give it a slight boost. Then keep adding relative force every FixedUpdate for that missile.

public float forcePerSecond = 10.0f; 

void FixedUpdate()
{
    rigidbody.AddRelativeForce(0, 0, forcePerSecond * Time.fixedDeltaTime);
}
more ▼

answered Mar 15 '11 at 07:18 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x24
x4

asked: Mar 15 '11 at 07:11 PM

Seen: 668 times

Last Updated: Mar 15 '11 at 07:11 PM