Shooting a cannonball

Hi, i want to do a game like peggle. I have a rotative cannon and a ball. The ball lauch but don’t lauch in the direction of the cannon. The ball just drop down. I would like that the ball lauch in the direction the cannon is pointing.
Here is what i have for now:

using UnityEngine;

using System.Collections;

public class lancer : MonoBehaviour {

public Transform bouton;
public Transform balle;
public bool lance = false;
public Rigidbody projectile;

void OnMouseDown()
{
if (lance == false)
	{
	projectile.rigidbody.AddForce(Vector3.forward * 10, ForceMode.Impulse);
	balle.rigidbody.useGravity = true;
	lance = true;
	}
}

}

1 Answer

1

You want to make sure you are using your AddForce on the correct direction. So you should use something like: cannon.transform.forward, where cannon is a reference to your cannon gameObject or transform.