You've already forked taptap2024_GJ_chidouren
增加功能
This commit is contained in:
@@ -1,14 +1,34 @@
|
||||
using UnityEngine;
|
||||
using Framework.Utils.Extend;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component
|
||||
{
|
||||
public class PlayerEntity : MonoBehaviour
|
||||
{
|
||||
public float speed = 10;
|
||||
|
||||
public Rigidbody2D rigidbody2D;
|
||||
public void OnMove (Vector2 vector)
|
||||
{
|
||||
this.transform.Translate (vector * speed * Time.deltaTime);
|
||||
var t = this.transform;
|
||||
// 获取前方方向的世界坐标
|
||||
Vector3 forward = (Vector3)vector;
|
||||
//根据遥感向量获取一个0,1的移动速度系数
|
||||
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);
|
||||
// this.transform.Translate ( Vector3.up * speedOffset * speed * Time.deltaTime);
|
||||
this.rigidbody2D.MovePosition (t.position + ((Vector3)vector * speed * Time.deltaTime));
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user