doug basic movement

This commit is contained in:
2025-06-19 20:08:27 -05:00
parent 2445e14457
commit 33bf1663aa
10 changed files with 981 additions and 20 deletions
+36
View File
@@ -0,0 +1,36 @@
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public GameObject DougBody;
public float walkSpeed;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
RotatePlayerTowardMouse();
Walk();
}
void Walk()
{
transform.position += DougBody.transform.forward * Input.GetAxis("Vertical") * walkSpeed * Time.deltaTime;
transform.position += DougBody.transform.right * Input.GetAxis("Horizontal") * walkSpeed * Time.deltaTime;
}
void RotatePlayerTowardMouse()
{
Vector2 positionOnScreen = Camera.main.WorldToViewportPoint(DougBody.transform.position);
Vector2 mouseOnScreen = (Vector2)Camera.main.ScreenToViewportPoint(Input.mousePosition);
float angle = Mathf.Atan2(positionOnScreen.y - mouseOnScreen.y, positionOnScreen.x - mouseOnScreen.x) * Mathf.Rad2Deg;
DougBody.transform.rotation = Quaternion.Euler(new Vector3(0f, -(angle + 90), 0f));
}
}