I am currently working with 2D rigid bodies, and I seem to encounter the problem of having the ability to jump on walls as well as jumping while rotated. What would be the best method of preventing my player from doing this? Here is the script that I am currently using:
using UnityEngine;
using System.Collections;
public class CubeMovement : MonoBehaviour {
float maxSpeed = 4.0F;
bool isGrounded;
int moveSpeed = 15;
int jumpSpeed = 600;
void OnCollisionEnter2D (Collision2D col) {
if (col.gameObject.tag == "Ground") {
isGrounded = true;
}
}
void OnCollisionExit2D (Collision2D col) {
if (col.gameObject.tag == "Ground") {
isGrounded = false;
}
}
void OnTriggerEnter2D (Collider2D other) {
if(other.gameObject.tag == "Divider") {
Application.LoadLevel(Application.loadedLevel);
}
}
void FixedUpdate () {
if (Input.GetMouseButton(0)) {
if(rigidbody2D.velocity.x > -maxSpeed) {
rigidbody2D.AddForce(-Vector2.right * moveSpeed);
}
}
if (Input.GetMouseButton(1)) {
if(rigidbody2D.velocity.x < maxSpeed) {
rigidbody2D.AddForce(Vector2.right * moveSpeed);
}
}
if(Input.GetKeyDown(KeyCode.Space))
{
if (isGrounded) {
rigidbody2D.AddForce(Vector2.up * jumpSpeed);
}
}
}
}