Hi everyone
So I have this script below that determines the players rotation in the direction its heading. How do i add a If mouse down function to addForce to its current trajectory?
Any help would be greatly appreciated!!!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerVelocity : MonoBehaviour {
Vector3 startPos, endPos, direction;
public Rigidbody2D myRigidbody;
public float thrust = 10.0f;
void Start()
{
myRigidbody = GetComponent<Rigidbody2D> ();
transform.position = new Vector3(0.0f, -2.0f, 0.0f);
}
void Update () {
Vector2 moveDirection = myRigidbody.velocity;
if (moveDirection != Vector2.zero) {
float angle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
}
}