Answer the question
In order to leave comments, you need to log in
Top-Down 2D game. How can I make it look left when the character walks to the left?
Here is the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody2D rb;
private Vector2 moveVelocity;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
moveVelocity = moveInput * speed;
}
void FixedUpdate()
{
rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
}
}
Answer the question
In order to leave comments, you need to log in
if (Input.GetKey(KeyCode.A))
{
speedX = -horizontalSpeed;
transform.localScale = new Vector3(-1, 1); //Персонаж смотри в ту сторону, куда нажал игрок
}
else if (Input.GetKey(KeyCode.D))
{
speedX = horizontalSpeed;
transform.localScale = new Vector3(1, 1); //Персонаж смотри в ту сторону, куда нажал игрок
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question