Question by
Tristan_ist_ein_Name · Sep 03, 2017 at 12:09 PM ·
c#rigidbodyjump
How can I make Jumps smooth?
The Character is somehow teleporting up and not moving up, even though I've changed the velocity and not the position.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed;
public float jump;
private float nextJump = 0.5F;
public float jumpRate = 0.5F;
public float jumpForce;
// Movement Script
void FixedUpdate()
{
Rigidbody2D rigidbody = gameObject.GetComponent<Rigidbody2D>();
float moveHorizontal = Input.GetAxis("Horizontal");
Vector2 movement = new Vector2(moveHorizontal, jump);
rigidbody.velocity = movement * speed;
//Jump Script
if (Input.GetButtonDown("Jump") && Time.time > nextJump)
{
rigidbody.velocity = new Vector2(0, jumpForce);
nextJump = Time.time + jumpRate;
}
}
}
Comment