Answer the question
In order to leave comments, you need to log in
Why does the 2d character fall very slowly and not jump?
Gravity is normally set, if you comment out the movement line, then everything will be fine
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayeMoving : MonoBehaviour
{
public Vector2 direction;
public Transform transform;
public float speed = 5f;
public PlayerControls playerControls;
public bool isGrounded = false;
public Rigidbody2D rb;
public float jumpForce = 5f;
private void Awake()
{
playerControls = new PlayerControls();
}
public void DirectOn(InputAction.CallbackContext context)
{
direction = context.ReadValue<Vector2>();
}
public void Jump(InputAction.CallbackContext context)
{
if (isGrounded)
{
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}
}
private void FixedUpdate()
{
rb.velocity = new Vector2(direction.x * speed, direction.y * speed);
}
void Update()
{
//transform.Translate(direction * Time.deltaTime * speed);
//rb.MovePosition((Vector2)transform.position + (direction * speed ));
}
private void OnCollisionExit2D(Collision2D coll)
{
if (coll.gameObject.CompareTag("Platform"))
{
isGrounded = false;
}
}
private void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.CompareTag("Platform"))
{
isGrounded = true;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question