

GetComponent ().velocity = new Vector2 (moveVelocity, GetComponent ().velocity.y) If (Input.GetKey (Ke圜ode.RightArrow) || Input.GetKey (Ke圜ode.D)) If (Input.GetKey (Ke圜ode.LeftArrow) || Input.GetKey (Ke圜ode.A))

GetComponent ().velocity = new Vector2 (GetComponent ().velocity.x, jump) If (Input.GetKeyDown (Ke圜ode.Space) || Input.GetKeyDown (Ke圜ode.UpArrow) || Input.GetKeyDown (Ke圜ode.Z) || Input.GetKeyDown (Ke圜ode.W)) Public class PlayerController : MonoBehaviour R2d.velocity = new Vector2((moveDirection) * maxSpeed, ) ĭebug.DrawLine(groundCheckPos, groundCheckPos - new Vector3(0, colliderRadius, 0), isGrounded ? een : Color.red) ĭebug.DrawLine(groundCheckPos, groundCheckPos - new Vector3(colliderRadius, 0, 0), isGrounded ? een : Color.This code will keep on jumping even though it is not on the ground how do you stop this (using Unity). T.localScale = new Vector3(Mathf.Abs(t.localScale.x), t.localScale.y, ) įor (int i = 0 i < colliders.Length i++) MoveDirection = Input.GetKey(Ke圜ode.A) ? -1 : 1 R2d.collisionDetectionMode = CollisionDetectionMode2D.Continuous ĬameraPos = Public class CharacterController2D : MonoBehaviour

Create another GameObject, call it "player_sprite" and add the Sprite Renderer component to it.Create a new GameObject and call it "Player".Open Scene with your 2D level (make sure the level sprites have 2D colliders attached, so the player won't fall through).The controller will be physics-based and will use a Rigidbody2D component. To make a 2D Platformer Character Controller in Unity, follow the steps below. 2D Platformer is a type of game where the player jumps between platforms, avoids obstacles, fights enemies, all of which is observed from a 2D side-view perspective.
