Im still trying to make my collectathon platformer and am STILL trying to make the Jump Height vary based off of the length the Jump Button is held down but it still jumps at the exact same heigths
The code is below, any ideas asto what Im doing wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
[Header("Movement and Game Feel")]
[Range(3,10)]
public int speed = 5;
[Range(3, 10)]
public int jumpForce = 4;
public LayerMask ground;
[Min(0.05f)]
public float checkForGround = 1.5f;
private Rigidbody character;
private bool isGrounded;
private bool isJumping = false;
private bool jumpIsPressed;
private float moveX;
private float moveZ;
// Start is called before the first frame update
void Start()
{
character = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
RaycastHit groundDetected;
isGrounded = Physics.Raycast(transform.position, Vector3.down, out groundDetected, checkForGround, ground);
inputformove();
movements();
}
void inputformove()
{
moveX = Input.GetAxis("Horizontal");
moveZ = Input.GetAxis("Vertical");
jumpIsPressed = Input.GetButtonDown("Jump");
}
void movements()
{
character.velocity = new Vector3(moveX * speed, character.velocity.y, moveZ * speed);
if(isGrounded && jumpIsPressed)
{
isJumping = !isJumping;
character.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
if(isJumping = true && Input.GetButtonUp("Jump"))
{
jumpPhysics();
}
}
}
private void jumpPhysics()
{
if(isJumping)
{
if(character.velocity.y > 0.25f)
{
jumpForce = jumpForce / 2;
}
else if(character.velocity.y > 0.0f)
{
jumpForce = jumpForce / 3;
}
}
}
}