0 votes

(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!

Godot version 3.1.1
in Engine by (17 points)

1 Answer

0 votes
Best answer

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 getangleto() 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.

by (559 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.