Question by
Undeadmax · Oct 14, 2020 at 09:26 AM ·
2d game2d-platformer2d sprites2d animation
How do i flip my character in 2D platformers,Im at a loss on flipping my 2D character
So im new to unity and im trying to make a platformer as simple and understandable as possible for myself and im at a loss on flipping the character horizontally, here is my move script plz help :).
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Move2DMax : MonoBehaviour { // Adds speed controller under script. public float MovementSpeed = 5f; // Adds jumpforce controller under script. public float JumpForce = 3f; // Grabs reference too players rigidbody(phyisics). private Rigidbody2D _rigidbody;
// Start is called before the first frame update.
void Start()
{
_rigidbody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame.
void Update()
{
// Gets Horizontal axis and does -1 for a key and +1 for d key.
// Vector3 has XYZ(Example-- 0,0,0) Vector2 is XY (Example-- 0,0)
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement,0,0) * Time.deltaTime * MovementSpeed;
if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f)
{
// Adds a vertical force and tells the script to only allow one jump at a time "Impulse"
_rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
}
}
} ,
Comment
Your answer
Follow this Question
Related Questions
2D Dynamic Lights and Shadows 0 Answers
Increase attack speed and animations 1 Answer