I am sorry for stupid question, but I am new to Unity trying this tutorial:
I have added player which is an animation of 8 sprites. When I attach a script to move the player, after I press the button it moves, but only by x,y and after I release the key, it returns to its original position. No real change in the code, except it is Animator insted of simple sprite. When I remove the animator, it works. For this to work I have to use r2d.AddForce(), also it moves absurdly slow, I have to set speed to 1500, 1500 to move normal.
For enemies from the tutorial it works fine, even those are animations. Any advice?
Thanks, Martin
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
public Vector2 speed;
private Vector2 movement;
private Rigidbody2D r2d;
public PlayerScript()
{
speed = new Vector2(50, 50);
}
void Start()
{
r2d = GetComponent<Rigidbody2D>();
}
void Update()
{
float inputX = Input.GetAxis("Horizontal");
float inputY = Input.GetAxis("Vertical");
this.movement = new Vector2(speed.x * inputX, speed.y * inputY);
}
void FixedUpdate()
{
//r2d.AddForce(movement);
r2d.velocity = movement;
}
}