(I’m new to Godot and game design in general)
I want the player to dash toward toward the mouse a set distance/location. I want the dash to feel fast so the time it takes is almost instant.
I’ve tried doing it by setting the velocity to something and then awaiting a timer function, but this feels really inconsistent with the distance of the dash. I can’t use tweening because I’m also using collisions and I find it makes it clip through the collision shapes.
Can you help me create a dash that feels snappy and consistent?
I have a variable that shows the target position, the problem is it hardly ever detects whether the player’s global position is equal to it. There’s also the problem of having the target position behind a wall and so the distance will never be reached. Is there a better way I can see the distance it has travelled?
If ypu have a fixed amount of time to reach the location then the physics is simple, but perhaps unrealistic
velocity = distance * time_to_dash
create a timer and set it to time out at time_to_dash.
Also make a radius of satisfaction around the target, so instead of position==target
You would use
if (target-position).length() < desired_range:
If you want constant speed then you need to compute the
time = distance / speed
and dynamically change the timer.
And use a raycast to check that there are no collisions
There is a Raycast3D node you can add to the scene. I would attach one to the player and call
%RayCast3D.is_colliding() to check for collisions. You could also attach an area3d to the target position and filter that in the collision function.
Also checkover the code to make sure the function cant be called if the player is already dashing, same with all updates to the target area.
Have a time limit and traveled distance limit. Once the dash is triggered - accumulate both. As soon as either of them is exhausted - stop the dash. That way you’ll normally go the wanted distance if there are no obstacles and stop dashing shortly anyway if you get stuck on an obstacle. No need for any complex setups or additional collision tests.
Character body “knows” the distance it travelled during the last frame. Although it needs to be length of what that call returns. Corrected the example code.
But it doesn’t really matter how you implement distance tracking. You can do it manually as well.
The gist is to track both - distance and time, and switch the dash off as soon as one of them crosses its limit.