Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Abanoub |
Currently I have the player moving towards the mouse position , using this example :
https://kidscancode.org/godot_recipes/3d/click_to_move/
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);
rotate_x(0.0);
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()) {
godot::Godot::print(std::to_string(distance_to_target).c_str());
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 ?