Hi, i’m trying to learn to instantiate, and to impulse an object forward.
In this case, i got a cannon, that instatiates a cannonball when pressing fire button, and i want to impulse the cannonball forward (just like a cannon ball does), but i’m cant figure out a solution… I’m a begginer with unity, and i could really use some help…
It’s hard to find the logic, but the cannon ball does not instatiate, and it’s not push forward.
Sorry for the bad english
using UnityEngine;
using System.Collections;
public class Disparar : MonoBehaviour {
public GameObject cannonBall;
public Transform spawn;
public float thrust;
public float gravity;
void Start () {
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Rigidbody clone;
clone = Instantiate(cannonBall, new Vector3(spawn.position.x, spawn.position.y, spawn.position.z), Quaternion.Euler(0f, 90f, 0f)) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * thrust);
}
}
}