Hello, guys! Here’s the deal:
I’ve got a 3d world with a 2d character in it (don’t let the screenshots fool you, I’ve enabled 2d for better observation). There is a capsule collider on the character. Here’s the code for it’s controller:
using UnityEngine;
using System.Collections;
public class JellyNew : MonoBehaviour {
private GameObject child;
public float maxSpeed = 5f; //Declare maximum speed
bool facingRight = true;
//Getting animator component from a child object
public GameObject childWithAnimation; //Declaring input for editor
Animator anim;
void Awake () {
anim = childWithAnimation.GetComponent<Animator> ();
}
//Ground Check
bool onGround = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround; //Declaring input for editor
public float jumpForce = 700f; //Declare jumping force
//bool doubleJump = false;
// Use this for initialization
void Start ()
{
child = GameObject.Find ("SpriteRotate"); //Finding a child which should be rotated
}
// Update is called once per frame
void FixedUpdate ()
{
onGround = Physics.CheckSphere(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool("Ground", onGround);
//if(onGround)
//doubleJump = false;
//How fast we're moving up or down
anim.SetFloat("vSpeed", rigidbody.velocity.y);
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs(move)); //This is our current vertical speed
rigidbody.velocity = new Vector2 (move * maxSpeed, rigidbody.velocity.y);
if(move > 0 &&!facingRight)
Flip();
else if(move < 0 && facingRight)
Flip();
}
void Update()
{
//If player on the ground and we're hitting 'Jump' button, we become no longer 'on the ground' and we're jumping
if(onGround && Input.GetButtonDown("Jump"))
{
anim.SetBool ("Ground", false);
rigidbody.AddForce (new Vector2(0,jumpForce));
}
}
void Flip() //This hideous, yet effective function rotates the child object with sprite and animation
{
facingRight = !facingRight;
Vector3 childScale = child.transform.localScale;
childScale.x *= -1;
child.transform.localScale = childScale;
}
}
When I stand on a step and jump, I jump just as I intend to - not too high up. That’s the correct version. Here’s a screen of a normal jump:
THE PROBLEM: When I run towards the stairs and jump off of one step’s edge, the character jumps enormously high. You can see how high he jumps on this screen:
What’s the problem with this all?