I’m making a 2d platformer where you can launch yourself towards the place where the player clicks. I’m new to unity and none of the answered questions here seem to solve my problem. I’m using a rigidbody and the part of the script that won’t work is as follows:
void FixedUpdate () {
float move = Input.GetAxis(“Horizontal”);
body.velocity = new Vector2(move * maxSpeed, body.velocity.y); //basic player movement
if (Input.GetMouseButtonDown(0)){
mousePos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
direction = (mousePos - body.position);
}
if (Input.GetMouseButtonUp(0))
{
direction.Normalize();
body.AddForce(direction * jumpForce);
}
For some reason the AddForce function does nothing to the player and I’m just clueless at the moment. Using other people’s code won’t work either because I’ve tried A LOT.