Question by
the_spyor_ · Feb 14, 2020 at 06:56 PM ·
c#2dmovement2d game
Why won't my 2D Sprite Move?
I put in a basic movement code, and now the sprite just barely moves, and I have no idea what's wrong. The code I used is below...`[SerializeField] private float _speed = 3.6f;
void Update()
{
transform.position = new Vector3(0, 0, 0);
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(horizontalInput, verticalInput, 0);
transform.Translate(direction * _speed * Time.deltaTime);
}`
Comment
Best Answer
Answer by Larry-Dietz · Feb 14, 2020 at 07:30 PM
You are resetting the position back to 0,0,0 at the start of each update cycle, so you are only going to se a slight movement then trying to move.
Eliminate that first line, and you should be moving just fine.
Hope this helps, -Larry
Your answer
Follow this Question
Related Questions
2D AI movement 0 Answers
Detect whether a Rigidbody collided with a Trigger 2 Answers
How can I make the character jump between the boxes? 0 Answers
Homing attack suggestion 0 Answers