统一使用3D精灵的机芯无法正常工作

问题描述

我已经使所有动作都与我的鬼魂一起工作了,那是一个红色的球,所以我做了一个精灵(我不确定那是否就是你所说的),但我现在不能动作了。 。它看起来像在冰上,因为当它试图转弯时它会变成对角线,而当它直行时它会加速。我不知道为什么要这样做,因为我什至没有在其中施加任何力量来移动它。 (代码):

 GameObject.Find("ghosteyes").transform.position = (place + vecmove);

谢谢

解决方法

所以您可以做的是三件事。首先获取您的变换,然后使用Translate这样移动它:

private Transform _transform;

private void Start()
{
    //this gets the transform that the script is on and sets it to _transform
    _transform = this.GetComponent<Transform>();
}



private void Update()
{
    float hor = Input.GetAxis("Horizontal");
    float vert = Input.GetAxis("Vertical");

    _transform.Translate(new Vector2(hor,vert));
}

OR 将Input添加到该位置以进行更固定的移动。

private Transform _transform;

private void Start()
{
    //this gets the transform that the script is on and sets it to _transform
    _transform = this.GetComponent<Transform>();
}



private void Update()
{
    float hor = Input.GetAxis("Horizontal");
    float vert = Input.GetAxis("Vertical");
    

    _transform.position += new Vector3(hor,vert) * Time.deltaTime; 
}

OR

在您的播放器上创建一个僵尸。然后将此脚本放到播放器上。并使用rigidbody.MovePosition移动角色。例如:

   private Rigidbody2D rb;

private void Start()
{
    rb = this.GetComponent<Rigidbody>();
    
}



private void Update()
{
    //This will take in horizontal input like A and D/ arrow left or right.
    float hor = Input.GetAxis("Horizontal");
    rb.MovePosition(transform.position += new Vector2(hor,0));
}