My case is:

We are developing a kart racing game, and the players are fighting with each other and trying to reach the finish line.

The thing is, I am confused over how to implement following logic:

The player has missile and grenade as weapons.

I can do missile lock, then the missile follows the enemy and hits the enemy with it. (Vector3.MoveTowards()).

But how would I do grenades?

Suppose both enemies and players are moving forward on the Z axis:

Case 1:

Player throws grenade at enemy.

It goes and hits enemy.

**I can do this the same way as missile logic.

Case 2:

Player throws grenade at enemy.

Enemy changes position on the X axis (right, left).

Grenade should not follow player to the next position.

**I am confused about this case: how to let grenade not change its position and get the blast on surface??

  • \$\begingroup\$ In case your grendade trajectory is simple parabola you can easily calculate initial velocity Vector3 needed to reach target point. Then somewhere in update loop you need to change grenade velocity based on gravitational acceleration and change its position based on velocity. \$\endgroup\$ – nikoliazekter Jun 1 '15 at 8:26
  • \$\begingroup\$ For those who are looking for similar thing,this script here work for me perfectly (with little modifications) forum.unity3d.com/threads/… \$\endgroup\$ – idurvesh Jun 2 '15 at 11:56

You could model the grenade as a conventional rigidbody with an initial speed and have it affected by gravity. Add a script with an OnCollision method to trigger when it touches a vehicle or the ground.


When throwing the grenade, take a copy of the enemy's original position Vector3. Move towards that instead of towards the enemy GameObject. Alternatively spawn in a pre-cache'd "GrenadeTarget" GameObject at the original enemy position as a marker and move the missile towards that.

  • \$\begingroup\$ Yes you are right.I tried that but thing is grande just stuck in the air. I have set target GO at Enemy's head as target (which all weapon follow), so with this cache technique, granade just goes and stuck in the air same as at height of enemy's head. \$\endgroup\$ – idurvesh Jun 1 '15 at 8:03
  • \$\begingroup\$ Well, if you've set the target to be the Head position then why would you expect the grenade not to land there? If you wish to get something decent I suggest researching a parabola arc implementation and targeting the original feet coordinate of your enemy. That way your grenade will follow the thrown arc from your player to the enemy's original location. \$\endgroup\$ – DanoThom Jun 1 '15 at 9:06
  • \$\begingroup\$ yes thanks @danothm ,I got it work with Parabola script available here here with little modifications, forum.unity3d.com/threads/… \$\endgroup\$ – idurvesh Jun 2 '15 at 11:57
  • \$\begingroup\$ great, glad to hear you got something working. Remember to accept an answer when you're satisfied. \$\endgroup\$ – DanoThom Jun 2 '15 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.