gpt4 book ai didi

c# - Vector3.MoveTowards 没有做它的事情

转载 作者:太空宇宙 更新时间:2023-11-03 22:44:26 25 4
gpt4 key购买 nike

当我使用 Vector3.MoveTowards 方法时,木板无法移动。我不完全确定为什么。有好心人来看看吗?

public class BrickMoveVErtical : MonoBehaviour 
{
public Vector3 positionOne, positiontwo, nextposition;
public Transform plankTranform;
public Transform positionBTransform;
public float speed;

void Start ()
{
positionOne = plankTranform.localPosition;
positiontwo = positionBTransform.localPosition;
nextposition = positiontwo;
}

void Update ()
{
move();
}
private void move()
{
plankTranform.localPosition = Vector3.MoveTowards(positionOne,nextposition,Time.deltaTime*speed);
if(Vector3.Distance(plankTranform.localPosition,nextposition)<0.1)
changeMovementPlank();
}
void changeMovementPlank()
{
nextposition = nextposition != positionOne ? positionOne : positiontwo;
}
}

最佳答案

您应该使用当前位置作为 current 参数:

plankTranform.localPosition = Vector3.MoveTowards(plankTranform.localPosition, nextposition,Time.deltaTime*speed);
^^^^^^^^^^^^^^^^^^^^^^^^^^^

关于c# - Vector3.MoveTowards 没有做它的事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50659620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com