#How do i make my character walk through walls and ceiling?

1 messages · Page 1 of 1 (latest)

covert vine
#

My character works fine with slopes and etc. But when i my character try to walk through a angle that is above 90 degrees (like in this curve, for example), my character gets stuck.

Arthuralgum
1d
Godot Version
Godot Engine v4.4.1.stable.steam.49a5bc7b6

Question
My character works fine with slopes and etc. But when i my character try to walk through a angle that is above 90 degrees (like in this curve, for example), my character gets stuck.

My movement code:

if player.is_on_floor():
floor_angle = player.get_floor_angle()
slope_factor = clamp(cos(floor_angle), 0.4, 1.0)
rot = floor_angle
player.velocity.x = motion.x * (1 + -0.5 * player.get_floor_normal().x)
player.velocity.y = motion.y * (1 + -0.5 * player.get_floor_normal().y)
if direction and !control_lock:
if player.is_on_floor():
if (direction > 0 and motion.x >= 0) or (direction < 0 and motion.x <= 0):
if abs(motion.x) <= topspeed:
motion.x += acc * 0.25 * direction
else:
motion.x = topspeed * direction
else:
motion.x += 0.25 * direction * delta * 120
else: # If mid-air...
motion.x += (acc) * direction * delta * 60

And my CharacterBody3D max angle is 180 degrees. Does anyone know a way to solve this problem?

digital quarry
unkempt blaze
#

Maybe
var is_player_on_surface: bool = player.is_on_floor() or player.is_on_wall() or player.is_on_ceiling()

Then change any floor specific functions to more general ones. Like instead of getting floor normal get collision normal from last slide collision.

covert vine
#

Something like this?
var is_on_surface: bool = player.is_on_floor() or player.is_on_wall() or player.is_on_ceiling()
print(is_on_surface)
if is_on_surface:
floor_angle = player.get_floor_angle()
slope_factor = clamp(cos(floor_angle), 0.4, 1.0)
rot = floor_angle
player.velocity.x = motion.x * (1 + -0.5 * player.get_floor_normal().x)
player.velocity.y = motion.y * (1 + -0.5 * player.get_floor_normal().y)
if direction and !control_lock:
if is_on_surface:
if (direction > 0 and motion.x >= 0) or (direction < 0 and motion.x <= 0):
if abs(motion.x) <= topspeed:
motion.x += acc * 0.25 * direction
else:
motion.x = topspeed * direction
else:
motion.x += 0.25 * direction * delta * 120
else: # If mid-air...
motion.x += (acc) * direction * delta * 60

If so, it didn't work...