- Home /
My character does not want to flip
My character does not want to flip after I added animations for it. The weird thing is that the flip script is working perfectly fine when I don't add animations. Could anyone please help me? I am really trying to make a game but I don't have any idea how to fix this. I'll now leave the script :
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Security.Cryptography;
using UnityEngine;
public class PlayerController1 : MonoBehaviour
{
public float speed;
public float jumpForce;
public float moveInput;
private float jumpPressedrememberTime = 0.2F;
private float JumpPressedRemember = 0;
private bool isDashing = false;
private bool FacingRight = true;
private Rigidbody2D rb;
private bool isGrounded;
public Transform groundCheck;
public float checkRadius;
public LayerMask whatIsGround;
public AudioSource spaceSound;
private int extraJumps;
public int extraJumpValue;
private Animator anim;
void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
void Flip()
{
FacingRight = !FacingRight;
Vector3 Scaler = transform.localScale;
transform.localScale = Scaler;
Scaler.x *= -1;
}
void FixedUpdate()
{
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
void Update()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
if (moveInput == 0)
{
anim.SetBool("isRunning", false);
}
else
{
anim.SetBool("isRunning", true);
}
if (moveInput > 0)
{
Flip();
}
else if (moveInput < 0)
{
Flip();
}
if (isGrounded == true)
{
anim.SetBool("isJumping", false);
extraJumps = extraJumpValue;
} else
{
anim.SetBool("isJumping", true);
}
jumpPressedrememberTime = Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0)
{
JumpPressedRemember = jumpPressedrememberTime;
anim.SetTrigger("takeOf");
spaceSound.Play();
rb.velocity = Vector2.up * jumpForce;
extraJumps--;
}
else if (Input.GetKeyDown(KeyCode.Space) && extraJumps == 0 && isGrounded == true)
{
rb.velocity = Vector2.up * jumpForce;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
export max to unity ??? 2 Answers
Script not obeying? 2 Answers
Unity not recognizing true statement. 1 Answer
How to get an object to turn around/flip at a certain point 2 Answers
CircleCollider2D falling through edgeCollider2D when flipping? 0 Answers