- Home /
jump not working,Code for jump isn't working, help!
I'm currently working on a game for BPA ((business professionals of America And this code is for a character that needs to move left, right and jump. Right now the character can indeed move left and right and the animations look good! And I do have the animation for the jump down already. I was following a outdated tutorial for a while but my classmate helped me out with getting it to work, but the one thing we cannot figure out is the jump. I made a ground check, and a bool for ground. All I need now is for the jump to work along with the animations, it would mean a lot if someone could help. Here's my code! Extra info would be this is a 2d game and what not.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CInnabunController : MonoBehaviour {
public float maxSpeed = 8f;
bool left = true;
Animator a;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpForce = 700f;
void Start () {
a = GetComponent<Animator> ();
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
a.SetBool ("Ground", grounded);
a.SetFloat ("vSpeed", GetComponent<Rigidbody2D>().velocity = new Vector2 (0f,3f));
float move = Input.GetAxis ("Horizontal");
a.SetFloat ("Speed", Mathf.Abs (move));
GetComponent<Rigidbody2D> ().velocity = new Vector2 (move * maxSpeed, GetComponent<Rigidbody2D> ().velocity.y);
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.position += Vector3.left * maxSpeed * Time.deltaTime;
}
else if (Input.GetKey (KeyCode.RightArrow)) {
transform.position += Vector3.right * maxSpeed * Time.deltaTime;
}
if (move > 0 && left)
Flip ();
else {
if (move < 0 && !left)
Flip ();
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow) && GetComponent<Rigidbody2D>().velocity = new Vector2(0f,3f)){
a.SetBool ("Ground", false);
}
}
void Flip()
{
left = !left;
Vector3 scale = transform.localScale;
scale.x *= -1;
transform.localScale = scale;
}
}
// GetComponant().velocity = new Vector3 (x,y,z) float = f,
Answer by deyermand100 · Dec 19, 2017 at 01:47 PM
edit: this seems to be the line that is causing errors, not sure if this will help but here
if (Input.GetKeyDown(KeyCode.UpArrow) && GetComponent().velocity = new Vector2(0f,3f)){ ((line 68))
Your answer
![](https://koobas.hobune.stream/wayback/20220612144846im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to force a player to jump? 2 Answers
Why won't this jump code work? 1 Answer
Jump Script Not working (3D) 2 Answers
Jumping not always work 2 Answers
Box collider didn't jump with player 1 Answer