- Home /
Question by
sedatyavuz013 · Feb 25, 2021 at 05:23 PM ·
movementmousepositionscreentoworldpoint
Mouse position for player movement
if (Input.GetMouseButtonDown(0))
{
startPos = Input.mousePosition;
}
if (Input.GetMouseButtonUp(0))
{
animator.SetBool("run", false);
}
if (Input.GetMouseButton(0))
{
animator.SetBool("run", true);
direction = (Vector2)Input.mousePosition -startPos;
direction = Vector3.Normalize(direction);
moveDirection.x = direction.x;
moveDirection.z = direction.y;
moveDirection.y = 0;
newDir = Vector3.RotateTowards(transform.forward, moveDirection, 0.3f, 0);
transform.rotation = Quaternion.LookRotation(newDir);
VeloMoveDirection = moveDirection * Time.deltaTime * PCspeed;
rb.velocity = new Vector3(VeloMoveDirection.x, rb.velocity.y, VeloMoveDirection.z);
}
The editor works too. Windows build does not work either. I think the solution to the problem is the ScreenToWorld function, but I couldn't integrate it.
Comment