Predicting ending location of movement

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By indigo

I am making a game where the player character has the ability to dash around. The dash can go through walls IF AND ONLY IF the wall is short enough that the dash can fully traverse it.

This means, for example, if the dash moves 2 units, it can go through a 1 unit long wall but not a 3 unit long wall, to stop you from getting stuck in the wall.

This presents quite the programming challenge for me. At the moment, I’m trying to do the following in physics_process:

	
$DashChecker.position = (dash_velocity.normalized()*($DashTimer.time_left))*DASH_SPEED

		if not $DashChecker.get_overlapping_bodies():

			$GynethCollision.set_deferred('disabled', true)

		else:

			$GynethCollision.set_deferred('disabled', false)

		# if not, turn collision off so we can go through things

		# move the character

		var collision = move_and_collide(dash_velocity*delta)`

“DashChecker” is a Area2D with an attached collision box.

I’m trying to move the DashChecker to the projected end position of the dash, calculated by (dash_velocity.normalized()*($DashTimer.time_left-delta))*DASH_SPEED

Then, if the dashchecker collision box is not overlapping with anything, I turn off my character’s collision so that they can go through walls.

If the dashchecker IS overlapping with something, then I turn the collision on so that they’re unable to go through the wall.

The issue that I’m running into is that (dash_velocity.normalized()*($DashTimer.time_left))*DASH_SPEED doesn’t seem to be accurately calculating the end position. When dashing, the DashChecker keeps changing position. I would think that that equation would result in a constant global coordinate output, but apparently not.

Any insight into this problem? Why is my DashChecker not accurately predicting the end of the dash? Is there another way to go about this that’s way easier?

:bust_in_silhouette: Reply From: Andrea

if the checker is a child of the player node, it is obviously moving together with the player when dashing.
you may want to translate the checker using global_position instead of position