WEBLEB
Home
AI Editor
Login
Pro
English
English
Français
Español
HTML
CSS
JS
csharpusing UnityEngine; public class PlayerMovement : MonoBehaviour { // Physics parameters public float moveSpeed = 8f; public float jumpForce = 12f; // State variables private float horizontalInput; private bool isGrounded; // Component references public Rigidbody2D rb; public Transform groundCheck; public LayerMask groundLayer; void Update() { // Get left/right input (A/D or Arrow keys) horizontalInput = Input.GetAxisRaw("Horizontal"); // Check if player is touching the ground layer isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer); // Jump trigger if (Input.GetButtonDown("Jump") && isGrounded) { rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce); } } void FixedUpdate() { // Apply left/right velocity safely in physics step rb.linearVelocity = new Vector2(horizontalInput * moveSpeed, rb.linearVe
/* Replace with your JS Code (Leave empty if not needed) */
Preview
Open Advanced Editor
Publish Code
Full Screen
HTML
CSS
JS
csharpusing UnityEngine; public class PlayerMovement : MonoBehaviour { // Physics parameters public float moveSpeed = 8f; public float jumpForce = 12f; // State variables private float horizontalInput; private bool isGrounded; // Component references public Rigidbody2D rb; public Transform groundCheck; public LayerMask groundLayer; void Update() { // Get left/right input (A/D or Arrow keys) horizontalInput = Input.GetAxisRaw("Horizontal"); // Check if player is touching the ground layer isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer); // Jump trigger if (Input.GetButtonDown("Jump") && isGrounded) { rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce); } } void FixedUpdate() { // Apply left/right velocity safely in physics step rb.linearVelocity = new Vector2(horizontalInput * moveSpeed, rb.linearVe
/* Replace with your JS Code (Leave empty if not needed) */
Preview
Validating your code, please wait...