Question by
Unity-Artcraft · Apr 22, 2019 at 09:43 PM ·
jumpjumping
Jumping not working
I try to get my jumping to work but it doesn't... isGrounded is true so normally it should work...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerActions : MonoBehaviour
{
Rigidbody2D myRigid;
[SerializeField] float speed = 10;
[SerializeField] float jumpForce = 10;
[SerializeField] Transform groundCheck;
[SerializeField] float checkRadius = 0.5f;
bool isGrounded;
[SerializeField] LayerMask whatIsGround;
Collider2D myCollider;
private void Start()
{
myRigid = GetComponent<Rigidbody2D>();
myCollider = GetComponent<Collider2D>();
}
private void FixedUpdate()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
float moveInput = Input.GetAxisRaw("Horizontal");
myRigid.velocity = new Vector2(moveInput * (speed * Time.fixedDeltaTime * 100), 0.0f);
}
private void Update()
{
if (Input.GetButtonDown("Jump") && isGrounded == true)
{
myRigid.velocity = Vector2.up * jumpForce;
}
Debug.Log(isGrounded);
}
}
Comment
Your answer
Follow this Question
Related Questions
,Fps Controller jumps automaticalley 0 Answers
I am slowly falling down with the jump animation 4 Answers
While (starting jumping or in jump) holding W key makes game object jump high and fall slow. 1 Answer
Jump, if I touch button,Jump if I pres the touch button 0 Answers
How to double jump? i just can jump once when it touch the ground.. help me guys =D 1 Answer