- Home /
Question by
danielharush5252 · Apr 07, 2019 at 12:51 PM ·
characterfloating
Character is floating
using UnityEngine;
using System.Collections;
public class AutoMove : MonoBehaviour {
public float speed;
private void Update() {
transform.position = new Vector3((transform.position.x + speed), 0, 0);
}
}
When I go to play mode my character is floating:
settings: https://prnt.sc/n8n6b0
I have no idea why it happens, please help me.
Comment
Best Answer
Answer by xxmariofer · Apr 07, 2019 at 01:17 PM
Add a rigidbody2d component
I did that already and it didn't worked, (it was supposed to be there I just forgot to add it)
i was reading fast and i missed the error change the line of code to this since you are setting it to 0 in the update all the time
transform.position = new Vector3((transform.position.x + speed), transform.position.y, 0);