Hi I made a script for basic movement and it works however I do not like how my character jumps because it really fast goes up and then falls for much longer time. Please could you tell me what can I chancge to fix it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
public float moveSpeed = 5f;
public float jumpForce = 10f;
public float gravityModifier = 10f;
public float jumpTimeTimer = 0.35f;
public float maxJumpTime = 0.35f;
private float horizontalDirection;
private bool onGround;
private bool isJumping = false;
public LayerMask GroundMask;
public Transform feet;
Rigidbody2D rb;
CircleCollider2D circle;
void Start()
{
rb = GetComponent<Rigidbody2D>();
circle = GetComponent<CircleCollider2D>();
}
void Move()
{
horizontalDirection = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(horizontalDirection,0)*moveSpeed;
}
void Jump()
{
if(isJumping && onGround)
{
rb.velocity += Vector2.up * jumpForce;
}
if(isJumping)
{
rb.velocity += Vector2.up * jumpForce;
}
if(rb.velocity.y<0)
{
rb.velocity += Vector2.up * Physics2D.gravity.y * (gravityModifier-1) * Time.deltaTime;
}
}
void JumpDetection()
{
if(Input.GetKeyDown(KeyCode.Space)&& onGround)
isJumping = true;
if(Input.GetKey(KeyCode.Space) && isJumping)
if(jumpTimeTimer>0)
{
isJumping = true;
jumpTimeTimer -= Time.deltaTime;
}else{
isJumping = false;
}
if(Input.GetKeyUp(KeyCode.Space))
isJumping = false;
}
void GroundCheck()
{
onGround = Physics2D.OverlapCircle(feet.position,0.1f,GroundMask);
if(onGround)
jumpTimeTimer = maxJumpTime;
}
void FixedUpdate()
{
Move();
Jump();
}
void Update()
{
JumpDetection();
GroundCheck();
}
}
And those are my Rigidbody settings.