Need Help with Collision not Working Correctly in Platforming Game

Godot Version

4.2.2

Question

Hello everyone,

I made sure to follow the directions given to me on both the appropriate tutorials as well as in a private conversation with an expert about how to implement 2D platforming game physics Mario brothers style, but unfortunately the character never touches the platform and instead falls straight through, even though I told it to stop falling using global variables and all of that good stuff (which I know how to use already from other projects I made).

Can anyone please explain what I am missing/doing wrong in this particular case?

Thank you in advance.

Game for Download, titled “A Spring in Your Step”

No one is going to trust some file in a google drive. It could be anything.

Share the layout of your scene tree and the player script. Your problem could be:

  1. The platform has no collisionshape
  2. The player has no collisionshape
  3. They both have collisionshapes but the layers are not set properly
1 Like

share an screen shot or video.
but now check collision layers of platform and player.

Awesome help! Thank you guys as always!

Unfortunately, I cannot upload the scene layout files or the player script files directly, because the website doesn’t support it, and the ZIP I attached should be self-explanatory if the post didn’t explain it already - it’s just the game uploaded in full on my Google Drive, because of the fact the website doesn’t let me upload the files directly without some kind of hyperlink.

It’s annoying obviously, but as they say “that’s life/just the way the cookie crumbles”

I can attach screenshots however, so I will work on that now.

The video file uploads correctly/is supported, so that’s good news. I made sure the layers were all on the same Z layer when I checked, and that both objects had collision shapes that were the correct size, so I am not sure what else I am doing wrong.

You can copy and paste your script into the text field here in the post. Use the preformatted text button in the toolbar to properly format your code.

I should have specified what layers I was referring to. I was referring to the collision layers of your collision shapes. You can see them in the inspector.

Can you link the tutorial you followed? Maybe this will give some insights into how the scene is made up.

Awesome help as always. I will do all of those things you mentioned.

The tutorial I followed is the default one given in the offical manual for absolute beginners, this one:

Link to manual’s official 2D tutorial

I checked the collision layers for the collision shapes and in fact they are on the same Z index, so that’s weird.

The script for the player is this:

extends Area2D
class_name Player

@onready var _animation_player = $AnimationPlayer

@export var speed: float = 400 # how fast the player will move in pixels per second.
var screen_size: Vector2 # size of the game window.

# Called when the node enters the scene tree for the first time.
func _ready():
	screen_size = get_viewport_rect().size # Get size of viewport rectangle.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):

	if (Globals.playerbounceheight >= 0) and (Globals.playertouchingplatform == true):
		position.y -= (Globals.playerbounceheight) * delta
		Globals.playerbounceheight -= 5
	else:
		position.y += 120 * delta
	
func start(pos):
	
	position = pos
	show()

Hi, does anyone have any responses? I’m still stuck at what I am doing wrong.