Files
taptap2024_GJ_chidouren/Assets/Scripts/Game/Component/PlayerEntity.cs

34 lines
1.5 KiB
C#
Raw Normal View History

2024-10-16 16:43:53 +08:00
using Framework.Utils.Extend;
using UnityEngine;
2024-10-16 00:03:41 +08:00
namespace Game.Component
{
public class PlayerEntity : MonoBehaviour
{
public float speed = 10;
2024-10-16 16:43:53 +08:00
public Rigidbody2D rigidbody2D;
2024-10-16 00:03:41 +08:00
public void OnMove (Vector2 vector)
{
2024-10-16 16:43:53 +08:00
var t = this.transform;
// 获取前方方向的世界坐标
Vector3 forward = (Vector3)vector;
//根据遥感向量获取一个01的移动速度系数
float speedOffset = forward.magnitude;
Quaternion targetRotation = Quaternion.FromToRotation (Vector3.up , forward.normalized);
transform.rotation = Quaternion.Lerp (transform.rotation , targetRotation , 0.25f);
// Debug.DrawLine (transform.position , transform.position + forward , Color.magenta);
2024-10-17 00:46:27 +08:00
this.transform.Translate ( Vector3.up * speedOffset * speed * Time.deltaTime);
// this.rigidbody2D.MovePosition (t.position + ((Vector3)vector * speed * Time.deltaTime));
2024-10-16 16:43:53 +08:00
// Vector3 v = target.position - transform.position;
// v.z = 0; // 确保向量在2D平面上
// float angle = Vector3.SignedAngle(Vector3.up, v, Vector3.forward);
// Quaternion rotation = Quaternion.Euler(0, 0, angle);
t.position = t.position.SetZ (0);
}
public void OnMoveEnd ()
{
this.transform.rotation = Quaternion.Euler (0 , 0 , this.transform.rotation.eulerAngles.z);
2024-10-16 00:03:41 +08:00
}
}
}