The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hi all,

I have been trying to make this work all day. Seems simple but I'm new to game development (but not new to coding).

I got a location of the mouse click against a StaticBody (Ground) and that's working perfectly fine. Moving and rotating works for the first click only but subsequent click become worse and worse. 2nd click sometimes work.

My project is at https://github.com/sidbc/3DCharacterClickToMove

The particular code of the 'Player' attached below. Also a gif animation showing how it currently runs (white ball is showing the mouse click location) and how the first click works but not subsequent clicks: https://github.com/sidbc/3DCharacterClickToMove/blob/master/screencast_problem_1.gif


func _physics_process(delta):
    if moving == false:
        speed = 0
        return
    speed += acceleration * delta
    if speed > maxspeed:
        speed = maxspeed

    var transform_origin = transform.origin
    var distance_to = transform_origin.distance_to(destination)
    
    # Magic number 5, I don't know why but smaller number doesn't work???
    if distance_to > 5:
        move_and_slide(destination)
    else:
        moving = false

func _on_Ground_input_event(camera, event,  new_position, normal, shape_idx):
    if moving == false and event.is_action_pressed("ui_click"):
        moving = true
        destination = new_position
    elif moving == true and event.is_action_pressed("ui_click"):
        moving = false

Please help this newbie! :__(

Godot version 3.4.4
in Engine by (19 points)

1 Answer

0 votes
Best answer

Actually there's a much easier way to achieve this: https://www.youtube.com/watch?v=OJSQZZ6s5pY

by (19 points)
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 Frequently asked questions and 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 [email protected] with your username.