Trying To Rotate Player Along Walls With Radians For Swim/Drill Movement

Godot Version

4.3

Question

I’m trying to make a drill movement system so that the player moves in the rotation he’s pointing, it works and all, but I need the player to not be able to sit there pushing on walls and to move along them automatically like shown in the clip of the game “Pepper Grinder”.

Here’s my best explanation of the problems, I do not fully understand the kind of math I’m trying to do, so yeah…

Since I’m rotating my player using radians/PI, I believe I’m working with PI incorrectly, for example, PI is supposed to work like degrees so 360° is all the way around back to 0°. But when I print my “player_rotation_radians” it seems that PI is right and 0 is left, and when if go up the “player_rotation_radians” can be negative which doesn’t sound correct to me, and additionally the “player_rotation_radians” can exceed PI and can grow infinitely if i sit there and spin the player. The problem when i go and lerp_angle my “player_rotation_radians” to the walls angle + “90°” its exceeding PI.

Here’s a small demo project. Also includes a clip of the game “Pepper Grinder”: demo-dig-movement.zip - Google Drive
Here’s my code:

#if input
	if direction:
		#gradually change player_rotation_radians to angle of input direction vector
		player_rotation_radians = lerp_angle(player_rotation_radians, direction.angle_to(Vector2.UP), 0.05)

#gets the angle of the wall and adds 90 deg to its angle to match player's
var wall_angle_direction:Vector2 = get_wall_normal() 
var wall_angle:float = wall_angle_direction.angle_to(Vector2.DOWN)
	
for i in get_slide_collision_count():
	#if no input given
	if not direction:
		if player_rotation_radians > wall_angle:
			player_rotation_radians = lerp_angle(player_rotation_radians, (wall_angle+PI/2), 0.05)
		else:
			player_rotation_radians = lerp_angle(player_rotation_radians, (wall_angle-PI/2), 0.05)
	
#converts player_rotation_radians to an x and y vector
steer_rotation_direction.x = -cos(player_rotation_radians)
steer_rotation_direction.y = -sin(player_rotation_radians)
	
#accelerates player to boost speed and steers using steer_rotation_direction vector
velocity.y = move_toward(velocity.y, ((current_speed*2)*steer_rotation_direction.x), dig_acceleration)
velocity.x = move_toward(velocity.x, ((current_speed*2)*steer_rotation_direction.y), dig_acceleration)

PI is only a half-rotation, TAU (2*PI) is a full rotation.

1 Like

I was going by this video in my assumption: The Best Explanation of Pi Is it not correct in saying that PI is the full circumference? And that TAU is actually the full circumference of a circle, like 360°?

1 Like

Radians are related to the radius, circumference is ‘2π * radius’ or ‘π * diameter’. I am not really sure why, if we had diameterians then maybe π would be a full rotation

1 Like

Oh ok, I understand. Thanks!