Answer the question
In order to leave comments, you need to log in
The character in the game moves to the right of the specified point. What to do?
this is what is originally.
this is what becomes.
I'm a newbie myself, so if it's a stupid question, don't hit me.
In general, I tried to make a flip, but when I turned to the left, the character also turned and bounced a few cells.
Script:
public ControlTipe controlTipe;
public Joystick joystick;
public float speed;
public Animator anim;
public enum ControlTipe {PC,Android}
private Rigidbody2D rb;
private Vector2 moveInput;
private Vector2 moveVelocity;
private bool facingRight = true;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Start()
{
if (controlTipe == ControlTipe.PC)
{
joystick.gameObject.SetActive(false);
}
}
void Update()
{
if (controlTipe == ControlTipe.PC)
moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
if (controlTipe == ControlTipe.Android)
moveInput = new Vector2(joystick.Horizontal, joystick.Vertical);
moveVelocity = moveInput.normalized * speed;
if (moveInput.x == 0)
{
anim.SetBool("isRuning", false);
}
else
{
anim.SetBool("isRuning", true);
}
if (!facingRight && moveInput.x > 0)
Flip();
if (facingRight && moveInput.x < 0)
Flip();
}
void FixedUpdate()
{
rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
}
void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question