Question by
jono56667 · Apr 21, 2021 at 05:22 AM ·
c#movementjumpingthird-person
character stops moving when jumping
the jumping itself works okay its just when i jump it loses all forward moment and just jumps upwards.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class characterLocomotion : MonoBehaviour { Animator animator; Vector2 input;
Rigidbody RB;
public bool Grounded;
public float jumpForce;
public float XM;
public float YM;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
RB = GetComponent<Rigidbody>();
Grounded = true;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift))
{
if(Input.GetKey(KeyCode.W))
{
animator.SetBool("IsSprint", true);
}
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
animator.SetBool("IsSprint", false);
}
}
// Update is called once per frame
void FixedUpdate()
{
input.x = Input.GetAxis("Horizontal");
input.y = Input.GetAxis("Vertical");
animator.SetFloat("InputX", input.x);
animator.SetFloat("InputY", input.y);
if (Input.GetKey(KeyCode.Space) && Grounded)
{
RB.AddForce(input.x, jumpForce,input.y, ForceMode.Impulse);
animator.SetBool("Jump", true);
Grounded = false;
input.x = Input.GetAxis("Horizontal");
input.y = Input.GetAxis("Vertical");
}
if (Grounded == true)
{
animator.SetBool("Jump", false);
}
if(Grounded == false)
{
input.x = Input.GetAxis("Horizontal");
input.y = Input.GetAxis("Vertical");
}
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Terrain")
{
Grounded = true;
animator.SetBool("Jump", false);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Jump Using Raycast. 0 Answers
How can I prevent my jump from looping? 1 Answer
How can I make it so that the longer you hold down the jump button the higher the player jumps? 0 Answers
Issues Getting my GameObject to both Move Forward and Jump properly. 0 Answers
Need help with jumping on third person movement script. 0 Answers