0 votes

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 ?

Godot version 3.3
in Engine by (50 points)

1 Answer

0 votes

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)
by (80 points)

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

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.