2D platformer jump but with the mouse (Aim and Jump)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Melonad3

(Beginner)

How do i make the player jump with respect to mouse position ( towards my mouse )? I searched up a lot of videos in youtube but could’nt find any. Any suggestions will work. Thanks!

:bust_in_silhouette: Reply From: Merlin1846

Simply apply jumpForce as a vector rotated towards the mouse.

velocity += Vector2(jumpForce,0).rotated(get_angle_to(get_global_mouse_position()))

If that doesn’t work it may be because the get_angle_to() is using local coordinates instead, If that’s the case use this instead.

    velocity += Vector2(jumpForce,0).rotated(get_angle_to(get_local_mouse_position()))

Hope this helps, also remember to tell people what kind of object you’re using when it comes to physics whether it’s a kinematic, rigid, or custom.

Ah Thanks! The second one worked for me!
I’ll remember to put the kind of object in later questions.

Melonad3 | 2021-12-07 09:36

1 Like