When I use this code to let my character jump, it sometimes jump higher than other times. I am making a 2D platformer
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private float Speed = 15f;
private float JumpForce = 15000f;
public Rigidbody rb;
public Transform groundedEnd;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
Move();
Raycasting();
}
void FixedUpdate()
{
JumpKey();
}
void Move()
{
float Move = Input.GetAxis("Horizontal") * Speed;
Move *= Time.deltaTime;
transform.Translate(Move, 0, 0);
}
void JumpKey()
{
float JumpHeight = Input.GetAxisRaw("Jump") * JumpForce;
if (Input.GetKeyDown("space"))
{
rb.AddForce(transform.up * JumpHeight * Time.deltaTime);
}
}
void Raycasting()
{
Debug.DrawLine(this.transform.position, groundedEnd.position, Color.green);
}
}