unity
unity
void Update()
{
// Input from the player
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
// Move the player based on the input
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}
|||||||||||||||||||| PROJECT-2|||||||||||||||||||||||||
using UnityEngine;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
// Check if the player is grounded
isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.1f,
groundMask);
// Handle jumping
if (Input.GetKeyDown(jumpKey) && isGrounded)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
// Handle sliding
if (isSliding)
{
rb.AddForce(Vector2.right * slideForce * transform.localScale.x,
ForceMode2D.Impulse);
}
}
}