Player jitter when jump with Fixedupdate
I used fixed update in my player movement script , every thing is good , except Jumping , my player jitter when jump because of Fixed Update , when i use update it become better ... but i dont want to use update I want to use fixed update , can someone help can i use update and fixed update together? or can someone tell me how to use fixed update without getting any problem? this is my script :
public class PlayerMovement : MonoBehaviour {
public float _gravity = 1.5f;
public float _yVelocity = 0.0f;
public float _moveSpeed = 25.0f;
public float _jumpSpeed = 40.0f;
public CharacterController _controller;
private bool _onGround;
Animator anim;
void Start () {
_controller = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody>();
} void FixedUpdate () {
_onGround = _controller.isGrounded ; //Gets if the controller is grounded
Vector3 direction = new Vector3(SimpleInput.GetAxis("Horizontal"), _yVelocity, SimpleInput.GetAxis("Vertical"));
if (direction.sqrMagnitude > 1f) direction = direction.normalized;
Vector3 velocity = direction * _moveSpeed;
if (_onGround )
{
//JUMPING
if (CrossPlatformInputManager.GetButtonDown("Jump"))
{
_yVelocity = _jumpSpeed;
// rb.velocity += new Vector3(0 , _jumpSpeed , 0);
}
else
_yVelocity -= _gravity;
_controller.Move(velocity * Time.deltaTime);
Vector3 facingrotation = Vector3.Normalize(new Vector3(SimpleInput.GetAxis("Horizontal"), 0f, SimpleInput.GetAxis("Vertical")));
if (facingrotation != Vector3.zero) //This condition prevents from spamming "Look rotation viewing vector is zero" when not moving.
transform.forward = facingrotation;
} }
Your answer
Follow this Question
Related Questions
Detect if velocity equals 0? 2 Answers
[2D Platform Game] Precise Jumping Without Holding Down Directional Button. 0 Answers
Error CS0120 : An object reference is required to access non-static member 3 Answers
Navmesh interfering with mecanim jump animation (root motion) 1 Answer
Player looses ability to jump further right player moves. 1 Answer