Arc Jump not working

My character is a bunny, I want the user to have to hold down the s key for a few seconds to charge it, release it and the bunny goes in the direction of the mouse. I first got the mouse position, converted it to world coordinates, got the angle, normalized it to a 2d vector and applied the force to character through a RB. It works for the most part, but the bunny doesnt move horizontally left or right, only vertically, when your moving it works perfectly. While charging up the jump the player should be forced to stand still.

I want the arc to change depending on where the mouse is. So if the angle is close to the top (90 degrees) the jump height should be more pronounced, if its far right or left 0 or 180 then the jump distance should be more. This does happen when the player is moving.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

public class ArcJump : MonoBehaviour
    public Rigidbody2D rb;
    public float forceMagnitude = 10f;
    private bool isStandingStill = true;
    private Vector2 lastPosition;

    void Start()
        lastPosition = rb.position;

    void Update()
        // Check if the bunny is standing still
        if (rb.velocity.magnitude <= 0.1f && ((Vector2)transform.position - lastPosition).magnitude <= 0.01f)
            isStandingStill = true;
            isStandingStill = false;

        // Jump only if standing still and S key is pressed
        if (isStandingStill && Input.GetKeyDown(KeyCode.S))

        // Update last position for checking standing still status
        lastPosition = (Vector2)transform.position;

    void Jump()
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        mousePos.z = 0;

        Vector2 direction = mousePos - (Vector3)transform.position;
        float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
        float adjustedAngle = Mathf.Clamp(angle, 45f, 135f);

        float angleInRadians = adjustedAngle * Mathf.Deg2Rad;
        Vector2 normalizedVector = new Vector2(Mathf.Cos(angleInRadians), Mathf.Sin(angleInRadians));

        // Apply force only in the direction of the jump
        rb.velocity =;
        rb.AddForce(normalizedVector * forceMagnitude, ForceMode2D.Impulse);

Is this a perspective camera? If so, line 43 will always return on the camera's X position since you're passing the raw mouse position in.

Goes the docs for ScreenToWorldPoint for what the third term (the .z term) of the argument passed in should be.

To prove or disprove this, debug the values going through your code.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don't assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

How are you handling your character's horizontal movement when they are not jumping? Is it possible that you have some other script which is setting the horizontal velocity to 0 when the player is not pressing a direction?