Im creating a classic “Carnival” game where you launch a projectile at boxes to knock them of a shelf. The projectile is a prefab and gets “created” and launched straight forward.
I have tried to use transform.localRotation = Quaternion.Euler( Input.mousePosition.y, Input.mousePosition.x, 0.0f)
and then later rb.AddRelativeForce(x,y,z)
but this doesn’t work.
How can i fix this problem?
Here’s my script for the prefab:
public class CannonBallMovement : MonoBehaviour
{
Rigidbody rb;
public GameObject cannonBall;
public float strength;
public float height;
public float mousex;
public float mousey;
private void Awake()
{
mousex = Input.mousePosition.x;
mousey = Input.mousePosition.y;
transform.localRotation = Quaternion.Euler(mousey, mousex, 0f );
rb = gameObject.GetComponent(typeof(Rigidbody)) as Rigidbody;
}
void Start()
{
rb.AddRelativeForce(0.0f, height * Time.deltaTime * 50, strength * Time.deltaTime * 50);
}
}