Currenty I am using vectors to move my character , but when the character reaches the touch position it keeps moving forward , because the velocity has to slow down.
(当前,我正在使用矢量移动角色,但是当角色到达触摸位置时,它会继续向前移动,因为速度必须减慢。)
I want character to reach my fingers position ( which it is doing) , but then stop immediatly. (我希望角色到达手指位置(正在执行此操作),但要立即停止。)
Any suggestions? (有什么建议么?)
my code:
(我的代码:)
private float? pressX;
float currentX;
public float moveSpeed = 1f;
void Update()
{
if (Input.GetMouseButtonDown(0))
pressX = Input.touches[0].position.x;
else if (Input.GetMouseButtonUp(0))
pressX = null;
if (pressX != null)
{
float currentX = Input.touches[0].position.x;
// The finger of initial press is now left of the press position
if (currentX < pressX)
Move(-moveSpeed);
// The finger of initial press is now right of the press position
else if (currentX > pressX)
Move(moveSpeed);
// else is not required as if you manage (somehow)
// move you finger back to initial X coordinate
// you should just be staying still
}
void Move(float velocity)
{
transform.position += Vector3.right * velocity * Time.deltaTime;
}
ask by Marco123 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…