So i have a character that moves well and jumps fine while in idle but when it moves and jumps it stops running and jumps without contentiously moving, i have a 3rd person camera following the player from an angle … any help? here’s my code
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public float turnSmoothing = 15f;
public float speedDampTime = 0.1f;
public float jumpSpeed = 5f;
public float verticalVelocity = 0f;
public float jumpForce = 5f;
public bool grounded;
private Animator anim;
private HashIDs hash;
Rigidbody rb;
void Awake ()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody>();
hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<HashIDs>();
}
void FixedUpdate ()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
MovementManagement(h, v);
//
}
void Update ()
{
if(grounded && Input.GetButtonDown("Jump")){
Jump();
}
}
public void Jump(){
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
rb.AddForce( new Vector3(h, 10, v), ForceMode.Impulse );
rb.velocity += Vector3.up * jumpSpeed;
grounded = false;
anim.SetBool("Jump", true);
}
void OnCollisionEnter(Collision collision) {
grounded= true;
anim.SetBool("Jump", false);
}
void MovementManagement (float horizontal, float vertical)
{
if(horizontal != 0f || vertical != 0f)
{
Rotating(horizontal, vertical);
anim.SetFloat(hash.speedFloat, 5.5f, speedDampTime, Time.deltaTime);
}
else
anim.SetFloat(hash.speedFloat, 0);
}
public void Rotating (float horizontal, float vertical)
{
Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
Quaternion newRotation = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * Time.deltaTime);
rigidbody.MoveRotation(newRotation);
}
}