Question by
ngerbens · Jun 12, 2018 at 07:30 PM ·
lookatmousepositionscreentoworldpoint
Pointing direction with mouse problem. (CINEMACHINE)
Hello!
When I implement this code to my player it kind of works for a few seconds to direct my player flying through space. But after a few turns my Cinemachine vCam starts spinning in all directions. Does anybody know what I am doing wrong?
Transform myT;
public float movementSpeed;
private Vector3 mousePos;
private Vector3 aim;
void Update()
{
mousePos = Input.mousePosition;
mousePos += Camera.main.transform.forward * 100f;
aim = Camera.main.ScreenToWorldPoint(mousePos);
this.transform.LookAt(aim);
myT.position += myT.forward * movementSpeed * Time.deltaTime * Input.GetAxis("Vertical-");
}
Comment