Ok so I have my PlayerMovement controller going and have the character moving left and right, jumping, and double jumping. However after the character begins moving to the right the jumps get shorter and shorter. By the time you get to the 10th tile you no longer are able to jump at all. Any ideas on what this could be? There are no collision blocks causing it and none of the surrounding elements except the ground are considered solid.
Here is my PlayerMovement script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Transform playerTransform; //Player movement
public Rigidbody2D playerRigidBody; //Player jump
public int speed; //Controls how fast the character can move
//public int jumpHeight = 5;
private bool isFalling = false; //Check for character falling
//public Vector2 resetJumpHeight = new Vector2(0, 0); //Sets the jump height and locks it to where it only transforms the Y axis
public Vector2 jumpHeight = new Vector2(0, 15); //Sets the jump height and locks it to where it only transforms the Y axis
public bool isDoubleJumping = false;
public bool isOnGround = true; //Check if character is on the ground or in the air
private Animator myAnimator;
public int jumpCount = 0;
// Use this for initialization
void Start () {
playerTransform = GetComponent<Transform>();
playerRigidBody = GetComponent<Rigidbody2D>();
myAnimator.GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
//Move Player Right
if (Input.GetKey(KeyCode.D))
{
playerRight();
}
//Move Player Left
else if (Input.GetKey(KeyCode.A))
{
playerLeft();
}
//Player Jump
else if (Input.GetKey(KeyCode.Space))
{
playerJump();
}else if (Input.GetKeyUp(KeyCode.Space))
{
if (jumpCount != 3)
{
jumpCount = jumpCount + 1;
}
}
}
//Move Player Right
void playerRight()
{
playerTransform.Rotate(Vector2.right * speed * Time.deltaTime);
playerTransform.Translate(new Vector2(speed, 0) * Time.deltaTime);
//Player Jump while Moving Right
if (Input.GetKey(KeyCode.Space))
{
playerJump();
}
}
//Move player Left
void playerLeft()
{
playerTransform.Rotate(Vector2.left * speed * Time.deltaTime);
playerTransform.Translate(new Vector2(-speed, 0) * Time.deltaTime);
//Player Jump while Moving Right
if (Input.GetKey(KeyCode.Space))
{
playerJump();
}
}
//Player Jump
void playerJump()
{
if (isOnGround == true)
{
playerRigidBody.velocity = jumpHeight;
isOnGround = false;
}
if (isOnGround == false && jumpCount == 1)
{
//playerRigidBody.velocity = resetJumpHeight;
playerRigidBody.velocity = (playerRigidBody.velocity + (jumpHeight + jumpHeight));
jumpCount = 3;
isDoubleJumping = true;
}
else
{
}
}
//Test for ground collision
private void OnCollisionEnter2D(Collision2D collision)
{
isOnGround = true;
isDoubleJumping = false;
jumpCount = 0;
}
}