How to make player jump to mouse position

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

Currently I have the player moving towards the mouse position , using this example :

now how would I achieve jumping to the mouse position, currently my script is like this:

  void Player::move(const float &delta) {
            velocity.y += gravity * delta;
            if (target != godot::Vector3::ZERO) {
                look_at(target, godot::Vector3::UP);
                velocity = -get_transform().basis.z * speed;
                auto distance_to_target = get_transform().origin.distance_to(target);
                if (distance_to_target < 0.5) {
                    velocity = target = godot::Vector3::ZERO;
// weird behavior not what I'm looking for

                if (godot::Input::get_singleton()->is_action_pressed("Jump") && is_on_floor()) {
                    velocity.y = 100;
            velocity = move_and_slide(velocity, godot::Vector3::UP);

I tried messing around with velocity.y , but it always result in weird behaviors and the player when landing point/look at the floor.

how would I do it correctly ?

:bust_in_silhouette: Reply From: TTF DPC

Try this:

func _process(delta):
      find_path(self, get_global_mouse_position(), 100)

func find_path(node, body, Speed): 
    	var target = body.global_position
    	var velocity = node.global_position.direction_to(target) * Speed
    	if node.global_position.distance_to(target):
    		velocity = node.move_and_slide(velocity)
    	var distance = node.global_position.distance_to(target)

I already have the position, how to make the player jump towards it

Abanoub | 2021-05-21 22:54