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?
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.
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()