Question by
battleslayer · May 05, 2021 at 08:53 AM ·
c#jumping
When i jump in my FPS the player quickly teleports up and down. How let i jump smoothly?
Hello,
I am creating a FPS but when i jump the player quickly teleports up and down, but i want him to jump smoothly. When i fall down the gravity works fine. How do i fix this. I'm using a Character Controller for my player. Here is my script.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour { public CharacterController controller; public Transform player;
public float gravityMultiplier = 1f;
public float speed = 8f;
public float jumpHeight = 2.4f;
Vector3 movement;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
// Crouch
if (Input.GetButtonDown("Crouch"))
{
speed /= 3;
jumpHeight /= 1.5f;
player.transform.localScale *= 0.5f;
}
if (Input.GetButtonUp("Crouch"))
{
speed *= 3;
jumpHeight *= 1.5f;
player.localScale = player.transform.localScale / 0.5f;
}
movement = transform.right * x + transform.forward * z;
movement *= speed;
// Jump
if (Input.GetButtonDown("Jump") && controller.isGrounded)
{
movement.y = jumpHeight;
}
// Gravity
if (controller.isGrounded == false)
{
movement.y += Physics.gravity.y * gravityMultiplier;
}
// Movement
controller.Move(movement * Time.deltaTime);
}
}
How do i fix this?
Comment
Your answer
Follow this Question
Related Questions
How to double jump? i just can jump once when it touch the ground.. help me guys =D 1 Answer
Bugs on move in air(falling); 0 Answers
Unity 3D C# dash in backward direction 2 Answers
Raycast not changing value 0 Answers
Uneven Jump Heights 1 Answer