- Home /
Question by
anant_1910 · Jan 15, 2018 at 01:08 PM ·
rigidbodypositionquaternion2.5d
Problem with shooting projectiles
I am creating a 2.5d game using all the rigidbodies and I want to shoot a rigidbody cannon using my projectiles. So I am using mouse position to move the GameObject and i want to shoot a rigidbody at the same rotation as that os my gameobject Here is my character movement script
public class MouseController : MonoBehaviour {
[Header("Cannon")]
public GameObject cannonBall;
private float angle_mangle;
void FixedUpdate ()
{
Vector3 camPos = Camera.main.WorldToScreenPoint (transform.position);
Vector3 MouseDirection = Input.mousePosition;
MouseDirection.x = MouseDirection.x - camPos.x;
MouseDirection.y = MouseDirection.y - camPos.y;
MouseDirection.Normalize ();
angle_mangle = Mathf.Atan2 (MouseDirection.y, MouseDirection.x) * Mathf.Rad2Deg;
GetComponent<Rigidbody> ().MoveRotation (Quaternion.Euler (new Vector3 (0, 0, angle_mangle - 90)));
}
}
Comment