Godot Version
godot 4 web
so i am trying to make a small game as a side project and it has some pretty i would say not normal physics. basicly the player is a slime and i want them to basicly stick to walls floors or ceilings. i currently have the player rotate based on the floor angle its on using the get_floor_normal().angle() function. this works fine on the floor or on the ramps but the issue comes from the walls i just cannot get it to do the same. in code gravity should be disabled when hes on a surface and replaced with relative gravity and the movement should also be relative but it appears not to be. i have tried to get the jump relative but it also doesnt seems to work and when i am jumping it i hit the roof it rotates but not correctly it put the slime like 90 instead of 180.
ive been trying for 2 days but coudnt figure it out, please help
code:
var surfacerotation = 0
const SPEED = 60.0
const JUMP_VELOCITY = -400.0
var slimestate: String = “idle”
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
func _physics_process(delta):
# Add the gravity.
if not is_on_floor() and not is_on_wall() and not is_on_ceiling():
velocity.y += gravity * delta
else:
var relative_gravity = Vector2(0, gravity).rotated(rotation)
velocity += relative_gravity * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept"):
if is_on_floor() or is_on_wall() or is_on_ceiling():
var relative_jump = Vector2(0, JUMP_VELOCITY)
velocity = relative_jump
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
if Input.is_action_pressed("ui_left"):
if is_on_ceiling() or is_on_floor() or is_on_wall():
velocity.x = -SPEED
slimestate = "walking left"
$"slime sprite/slimeAnimationPlayer".play("slime walk left")
elif Input.is_action_pressed("ui_right"):
if is_on_ceiling() or is_on_floor() or is_on_wall():
velocity.x = SPEED
slimestate = "walking right"
$"slime sprite/slimeAnimationPlayer".play("slime walk right")
else:
if is_on_ceiling() or is_on_floor() or is_on_wall():
velocity.x = 0
$"slime sprite/slimeAnimationPlayer".play("slime idle")
slimestate = "idle"
if is_on_floor() or is_on_ceiling():
surfacerotation = get_floor_normal().angle()
if is_on_wall():
surfacerotation = get_wall_normal().angle()
rotation = surfacerotation + PI/2
Vector2(velocity).rotated(rotation)
move_and_slide()
also if it matters the colision stuff is tilemap