Hello,
I am currently at an impass with a script I am writing. Below is the code. As you can see, I am trying to find the angle for an object to point at so that it follows the mouse. I am very close to finishing this, but I am getting an error from my 27th line.
" Assets\CannonScript.cs(27,30): error CS7036: There is no argument given that corresponds to the required formal parameter ‘x’ of ‘Mathf.Atan2(float, float)’ "
cannonAngle = (Mathf.Atan2((realMouseLocation.x, realMouseLocation.y)) * Mathf.Rad2Deg);
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CannonScript : MonoBehaviour
{
public Vector3 mouseLocation = Vector3.zero;
public Vector3 realMouseLocation = Vector3.zero;
public Vector3 cameraLocation = Vector3.zero;
public float cannonAngle = 0.0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
mouseLocation = Input.mousePosition;
realMouseLocation = Camera.main.ScreenToWorldPoint(mouseLocation);
cameraLocation = CameraScript.CameraPosition;
cameraLocation.z = 0.0f;
realMouseLocation = realMouseLocation - (gameObject.transform.position - cameraLocation);
Debug.Log(realMouseLocation);
cannonAngle = (Mathf.Atan2((realMouseLocation.x, realMouseLocation.y)) * Mathf.Rad2Deg);
Debug.Log(cannonAngle);
}
}
Pretty please help me understand why this error is being thrown and what I am not understanding here. If you guys have a better way to complete this task please enlighten me.