0
\$\begingroup\$

I turn off fixed angle so my character can rotate, but it can only jump in 1 angle but I want it to jump in every angle.

How do I do that?

Code:

using UnityEngine;
using System.Collections;

public class Player: MonoBehaviour {

  public float maxspeed = 10f;
  bool facingRight = true;

  Animator anim;

  bool grounded = false;
  public Transform groundCheck;
  float groundRadius = 0.2f;
  public LayerMask whatIsGround;
  public Vector2 jumpDirection = new Vector2(0f, 0f);
  public float jumpFocre = 500f;
  bool doubleJump = false;

  void Start ()
  {
    anim = GetComponent<Animator> ();
  }

  void FixedUpdate () {
    grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
    anim.SetBool ("Ground", grounded);

    if (grounded)
      doubleJump = false;

    float move = Input.GetAxis ("Horizontal");
    anim.SetFloat ("Speed", Mathf.Abs (move));

    GetComponent<Rigidbody2D>().velocity = new Vector2(move * maxspeed, GetComponent<Rigidbody2D>().velocity.y);
  }

  void Update()
  {
    if((!doubleJump) && Input.GetKeyDown ("up"))
    {
      anim.SetBool("Ground", false);
      float move = Input.GetAxis ("Horizontal");
      jumpDirection.x = move;
      GetComponent<Rigidbody2D>().AddForce(jumpDirection.normalized * jumpFocre);

      if(!doubleJump && !grounded)
        doubleJump = true;
    }
  }

  void Flip()
  {
    facingRight = !facingRight;
    Vector3 theScale = transform.localScale;
    theScale.x *= -1;
    transform.localScale = theScale;    
  }
}
\$\endgroup\$
  • 1
    \$\begingroup\$ You have posted the LevelLoader code, is your current jump code in a different script? \$\endgroup\$ – Kelly Thomas May 2 '15 at 6:30
  • \$\begingroup\$ I don't have a different jump script, this is it. \$\endgroup\$ – user64751 May 2 '15 at 6:53