Question by
MrBob350z · May 14, 2016 at 09:45 PM ·
rigidbodyinstantiateaddforce
How can i make an object move to my aiming position?
Hi! I'm trying to learn about instantiate, and different types of forces, so i'm trying to make a cannon shoot a cannon ball, i've come to this.. It shoots the cannon ball, but i would want that the shot doesnt move always towards x axis, but instead, to move were the cannon is aiming, i leave my code and a picture that could help you guys, i'll apreciate your help :)
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"))
{
GameObject clone;
clone = (GameObject)Instantiate(cannonBall, spawn.position, Quaternion.Euler(0f, 90f, 0f));
clone.GetComponent<Rigidbody>().AddForce(thrust, gravity, 0f, ForceMode.Impulse);
}
}
}
bla.jpg
(283.9 kB)
Comment
Your answer
Follow this Question
Related Questions
Addforce is not working 1 Answer
Can't apply AddForce after Instantiating object 1 Answer
Ball Speed is not increasing as per code 0 Answers
GetAxis being missed in FixedUpdate work around? 1 Answer
RigidBogy.AddForce does nothing. 0 Answers