Why can't I jump?
I am following a tutorial on Youtube and the jump was working fine but I accidentally deleted some code but then I wrote it word for word back into my script now it won't work . No error messages, just it can't jump while the one in the video can
https://www.youtube.com/watch?v=1bHVsxw_o7o&t=3s![alt text][1]
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour { public float movementSpeed; public Rigidbody2D rb;
public float jumpForce = 20f;
public Transform feet;
public LayerMask groundLayers;
float mx;
private void Update()
{
mx = Input.GetAxisRaw("Horizontal");
if (Input.GetButtonDown("Jump") && isGrounded())
{
Jump();
}
}
private void FixedUpdate()
{
Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
rb.velocity = movement;
}
void Jump()
{
Vector2 movement = new Vector2(rb.velocity.x, jumpForce);
rb.velocity = movement;
}
public bool isGrounded()
{
Collider2D groundCheck = Physics2D.OverlapCircle(feet.position, 0.5f, groundLayers);
if (groundCheck != null)
{
return true;
}
return false;
}
}
,
I am following this Platformer tutorial on Youtube and the jump and Run was working fine until I dragged in my sprite. Now the code will not work and I can run but not jump
Using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour { public float movementSpeed; public Rigidbody2D rb;
public float jumpForce = 20f;
public Transform feet;
public LayerMask groundLayers;
float mx;
private void Update()
{
mx = Input.GetAxisRaw("Horizontal");
if (Input.GetButtonDown("Jump") && isGrounded())
{
Jump();
}
}
private void FixedUpdate()
{
Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
rb.velocity = movement;
}
void Jump()
{
Vector2 movement = new Vector2(rb.velocity.x, jumpForce);
rb.velocity = movement;
}
public bool isGrounded()
{
Collider2D groundCheck = Physics2D.OverlapCircle(feet.position, 0.5f, groundLayers);
if (groundCheck != null)
{
return true;
}
return false;
}
}