setting boundaries between floor and wall on a level

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

hi all,

i have a level and character and i’m trying to figure out how to set boundaries between the floor and wall so that the player cant walk beyond the edge of the floor (note the picture as example):

i watched a video and if you note at 2:55 into the video the person explains something about global position. this works except the issue is what if part of a wall is juxtaposing outwards? how would one add co-ordinates to that? here is the video:

much help would be appreciated thank you!

:bust_in_silhouette: Reply From: SnapCracklins

for global position, it’s pretty easy.

self.global_position

or if you want only the x or y:

self.global_position.x
self.global_position.y

I am doing a left-right game right now and essentially, i’d just write a script to stop movement whenever you hit a certain point. This method you would like want to place in your input and do a bit of tweaking, but it’s enough to start. (Assuming you’re using the classic vector math for player).

 if player.global_position.x > targetValue:
        playerVelocity.x = 0

You could also, alternatively, just put collisionboxes there as solo objects just to stop movement then shrink the box to where your player overlaps. Honestly, looking at this Final-Fight/Streets-of-Rage style, i think this option may work best and be the least headache, but that’s just me.

Game looks cool btw.

the issue is that my character has a jump mechanic and when he hits the collision box, he recoils and drops further down the screen.
im toying with using 3d but both 2d and 3d have their hurdles and i’m still new to scripting and godot.

someone on reddit suggested using the “move_along_path” method whereby this demo here:

2D Navigation Demo - Godot Asset Library

has a simple sprite with no collision. the sprite follows the a collision polygon path and the sprite moves beyond the path line.
so i decided to add a collision and convert it to a kinematic 2d and the sprite actually worked and moved beyond the edge of the collision lines.
now the issue is the game sprite moves by following a mouse click. just need to figure out how to remove the "follow_mouse " mechanic. anyway thanks for your response. much appreciated

chris33556 | 2022-07-04 06:07