- Home /
i can't move while jumping 2D
I started a month ago with unity. I am curently working on the animations and playermovement. Here is my script using System.Collections; using System.Collections.Generic; using UnityEngine;
public class playermovement : MonoBehaviour {
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("speed", Mathf.Abs(horizontalMove));
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("IsJumping", true);
}
}
public void Onlanding()
{
animator.SetBool("IsJumping", false);
}
void FixedUpdate ()
{
controller.Move(horizontalMove * Time.fixedDeltaTime ,false , jump);
jump = false;
}
}
Answer by B33bo_Astro · Nov 08, 2021 at 07:59 PM
if you're using brackey's character controller 2D script, you need to make sure that the 'WhatIsGround' variable inside the character controller 2d script is set to either 'everything' or 'ground'.
If you set it to ground. then only the ground will be jumpable, but you will have to set each ground object's layer to 'ground'
Your answer
Follow this Question
Related Questions
Player and Enemy Collision Problem 0 Answers
Player Movement in unity3d 1 Answer
Why can't i move after switching scene 1 Answer
player following touch position 0 Answers
Player returning 0 Answers