# How do I make my character jump in any angle?

My character is a square which can spin in any angle but it can not jump in certain angle.

Can anyone help?

public class Player: MonoBehaviour {

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

Animator anim;

bool grounded = false;
public Transform groundCheck;
public float jumpFocre = 500f;

bool doubleJump = false;

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

void FixedUpdate () {
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((grounded || !doubleJump) && Input.GetKeyDown ("up"))
{
anim.SetBool("Ground", false);

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

void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}


public float jumpFocre = 500f;
//...


Rigidbody2D.AddForce() takes a Vector2 as a parameter, so this can be changed to:

public Vector2 jumpDirection = new Vector2(0f, 1f);
public float jumpFocre = 500f;
//...


This will allow you to control both the magnitude and direction of the force applied for your jump by changing the values of jumpFocre and jumpDirection.

• I still can't jump.
– Bob
Apr 28, 2015 at 10:10
• jump direction should be modified otherwise your character will continue jump only on the y component. Apr 28, 2015 at 10:31
• How do I modified it?
– Bob
Apr 28, 2015 at 11:28
• (1,0) is right, (0,1) is up, (1,1) is halfway in between. Apr 28, 2015 at 11:32
• How do I add them together?
– Bob
Apr 28, 2015 at 12:07

Try something like this

public Vector2 jumpDirection = new Vector2(0f, 1f);
public float jumpFocre = 500f;
//...
float move = Input.GetAxis ("Horizontal");
jumpDirection.x = move;