[英]movement with 3D sprite in unity is not working
I had gotten all the movement working with my ghost, which was a red ball, so i made a sprite (im not sure if that is what you call it) i was able to make one but now the movement is not working.我已经用我的幽灵(一个红球)完成了所有运动,所以我制作了一个精灵(我不确定这是否是你所说的)我能够制作一个但现在运动不起作用。 it looks like it is on ice because when it tries to turn it goes diagonal and it speeds up when going straight.它看起来像是在冰上,因为当它试图转弯时,它会变成对角线,而直行时会加速。 I don't know why its doing this because i'm not even putting force into it to move it.我不知道它为什么这样做,因为我什至没有用力来移动它。 (the code): (编码):
GameObject.Find("ghosteyes").transform.position = (place + vecmove);
thanks谢谢
so what you can do is 3 things.所以你可以做的是三件事。 first get your transform,then move it using Translate like this:首先获取您的转换,然后使用 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 Add the Input to the position for a more fixed movement.或将输入添加到位置以获得更固定的移动。
private Transform _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或者
create a rigidBody on your player.在您的播放器上创建一个刚体。 then put this script on your player.然后将此脚本放在您的播放器上。 and use rigidbody.MovePosition to move your character.并使用rigidbody.MovePosition 移动你的角色。 for example:例如:
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));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.