I want to make a ball launch from a catapult mechanism when i press the space bar. How would i make it so that it has to be touching an object on the character so that it would move. Also how would I make it that it goes in the direction that the character is facing.
This is my code so far. I am using C#
using UnityEngine;
using System.Collections;
public class shooting : MonoBehaviour {
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.Space))
rigidbody.AddForce (Vector3.right * 100);
if (Input.GetKey (KeyCode.Space))
rigidbody.AddForce (Vector3.up * 70);
}
}