I need help to create a code to move the character, I've seen several tutorials but I'm having difficulties
Telling us what you're having difficulties with would help us help you. Tutorials are usually pretty good at explaining how you get simple 2d movement working so it's probably something specific blocking your progress
My problem is that I did a simple script to move to the right or left and change the face of the character to the side that is being moved by pressing one of the arrows on the keyboard but when pressed to the right the character usually moves to the right , but if pressed the left changes face, but continues to move to the right instead of the left my code: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { public float velocidade; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { movimentacao(); Debug.Log(transform.position); } void movimentacao() { if (Input.GetAxisRaw("Horizontal") > 0) { transform.Translate(Vector2.right * velocidade * Time.deltaTime); transform.eulerAngles = new Vector2(0, 0); } if (Input.GetAxisRaw("Horizontal") < 0) { transform.Translate(-Vector2.right * velocidade * Time.deltaTime); transform.eulerAngles = new Vector2(0, 180); } } }
i 'think' the issue is because you're turning your object around, then also moving it reverse. when you turn your object around, your positive becomes your negative and vice versa, so you simply always translate in the same direction (always + or always -). alternatively remove the angles.
As Primoz said it looks like the problem is you're turning your player around aswell as reversing the movement. Try just removing the minus before the vector2 on the moving left code
And how could I become a face of my character without negative and positive investor, I have no idea how I could do this
Instead of rotating the player change the localScale, if you change the x scale to a negative number it will flip the sprite. You can play around with that in the inspector to get an idea how it works. Also the sprite renderer has a flip sprite function built in https://docs.unity3d.com/ScriptReference/SpriteRenderer-flipX.html you can use this to change the direction aswell. So there is multiple ways you can achieve this. You will just have to try them out and see which works best for you