instantiate a object and "shoot" it at a certain direction

i will try to explain my situation:

the purpose of my game is to collect diamonds. the game world consists out of different “islands” where the diamonds are situated. You have to jump from island to island to collect the diamonds.

The diamonds should be placed randomly on these island. My thought was to create some sort of diamondcanon up in the air, that shoots diamonds to a random empty game object on one of these islands. i succeeded to shoot a diamond out of my canon with the following code:

var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation );

instantiatedProjectile.velocity =transform.TransformDirection( Vector3( 0, speed+numberOfDiamonds, 0 ) );

instantiatedProjectile.name="DiamondPrefab"+numberOfDiamonds;

my question is, how can i make the canon shoot at the direction of a certain game object. Now it just drops the diamond, but how can i “aim” the canon to a certain empty game object.

I hope my idea is the best way to achieve this, other suggestions are welcome as well.

Hi, welcome to the forum!

In general, it is difficult to target a rigidbody projectile exactly - the calculations are complicated and the physics engine itself can never simulate the motion perfectly. A simple way to mimic the trajectory of a launched object is to use a Bezier curve segment (see this thread for an implementation) to describe the path of motion. The Bezier curve doesn’t strictly give the right curve shape for a trajectory but gives a good impression nonetheless.