0 votes

Hey there, I'm fairly new to Godot - have read some of the Doc's.

I am making a 3D game with "click to move" functionality, I am using this script:
http://kidscancode.org/godot_recipes/3d/click_to_move/

Everything works perfectly EXCEPT once it arrives at its destination it jitters annoyingly, I tried LERP but still couldn't get the jitter to leave. one thing of note is that if i change the "close enough to target" distance to 2 instead of .5 it stops perfectly fine. I thought it might be the "moveandslide" function call reseting causing the jitter but the fact that it doesn't jitter after i change the distance to 2 has me puzzled.

My Player node(a seperate scene/ asset, velocity/movement script) is a child of my Floor node(static body, with script function for getting the clickposition). --if this is a problem let me know, i looked it up but couldn't find if it was.
^Just as I was typing this a thought occurred to me - could it be because the ground is a child mesh and that's where i'm "clicking" but the click
position isn't accurate as per the ground mesh?? as in i click on the ground but the Floor node is outputting a click_position value below the ground mesh, causing the cube to attempt to go through the ground, but collision is getting in the way causing stuttering? (probably overthinking it)

Any help would be extremely appreciated as I've been trouble shooting this issue ALL DAY and just want to move on with the project. Thanks in advance!

in Engine by (12 points)

1 Answer

+1 vote

It depends on the scale of your object and your speed. I suspect you have a larger speed than the one in the demo.

Imagine your speed is 5, and you are 3 units away from your target. This frame, you'll move 5 in the target's direction. Now you're 2 units away, but on the other side. So you'll move 5 units in that direction, and you're back to 3. This is what's happening (although I've exaggerated the values to illustrate).

To fix it, you can either:

1) halt movement within a certain distance of the target. This is fine if your speed is fairly low relative to your object's size. The difference will not be very visible. This is what the example is doing.

2) Ramp down your speed to 0 once you get within a certain distance. This will make it look like the object is braking to a stop at its target.

Either way, just as you choose a speed that works for you, you need to choose values of how close to get and/or how much to slow down.

Lastly, your guess about the "depth" factor is almost right, but it's about the height of your object. Your object's origin is its center, so if it's taller than 1 unit, then even when it's "at" the target location, the 3D distance between the object and the target is > 0.5.

by (20,913 points)

thanks for the fast response! i understand, but my speed and distance to target are exactly the same as in the code (speed = 5, < .5) and it still jitters, (however i'm not using a triangle but a cube instead and no marker - i'm assuming this is not the problem).

That brings me to the last point in your reply - are you referring to the ground plane (in my case a cube mesh with height of 2)? if i'm understanding correctly then i would have to change it to a height of 1 to fix the jitter? or is there some way to make the click_position value imitate the ground mesh? is there a way to fix this without changing either the dimensions of my player cube or the ground mesh? or am i way off? sorry if i am.

ah! sorry, i re-read your reply again and realized it's all connected. from what i can gather i can forget about the ground plane. instead, it's the size of my object in relation to my speed and distance from target. so if my player object is different in dimension than the one in the example, I need to adjust the speed and distance accordingly. correct?

and when you're referring to speed are you talking about the actual speed variable or the Vector3(velocity), because with a speed of 5 and the distance to target set to < 2 when i bring the velocity back to zero it just stops with no jittering, but that's to far away from the click_position.

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.