Question by
ReubenClare123 · Jun 19, 2019 at 07:23 PM ·
movementflippingleftidle
Sprite wont flips left when still. Need Help
Hi guys really need help. when still my sprite flips left and I need him to face the direction I press. Please help. Heres my script.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Animations;
public class PlayerPlatformerController : PhysicsObject { [HideInInspector] public bool facingRight = true; [HideInInspector] public bool jump = false;
public float maxSpeed = 7;
public float jumpTakeOffSpeed = 7;
public bool isFacingRight;
private SpriteRenderer spriteRenderer;
private Animator animator;
// Use this for initialization
void Awake()
{
spriteRenderer = GetComponent<SpriteRenderer>();
animator = GetComponent<Animator>();
}
protected override void ComputeVelocity()
{
Vector2 move = Vector2.zero;
move.x = Input.GetAxis("Horizontal");
move.y = Input.GetAxis("Vertical");
if (Input.GetButtonDown("Jump") && grounded)
{
velocity.y = jumpTakeOffSpeed;
}
else if (Input.GetButtonUp("Jump"))
{
if (velocity.y > 0)
{
velocity.y = velocity.y * 0.5f;
}
}
{
// Switch the way the player is labelled as facing
isFacingRight = !isFacingRight;
// Multiply the player's x local scale by -1
Vector3 theScale = transform.localScale;
theScale.x *= 1;
transform.localScale = theScale;
}
{
}
bool flipSprite = (spriteRenderer.flipX ? (move.x > 0.01f) : (move.x < 0.01f));
if (flipSprite)
{
spriteRenderer.flipX = !spriteRenderer.flipX;
}
animator.SetBool("grounded", grounded);
animator.SetFloat("velocityX", Mathf.Abs(velocity.x) / maxSpeed);
targetVelocity = move * maxSpeed;
}
}
public class Facing { }
Comment
Your answer
Follow this Question
Related Questions
Cube movement 0 Answers
problem with scripting movement 1 Answer
How to determine if an Enemy is moving left or right? 2 Answers
so how to i create a moving barrel 0 Answers
Unity 5 Movement swipe to left and right and up and down 0 Answers