Quantcast
Channel: Questions in topic: "left"
Viewing all articles
Browse latest Browse all 135

Sprite wont flips left when still. Need Help

$
0
0
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(); animator = GetComponent(); } 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 { }

Viewing all articles
Browse latest Browse all 135

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>