Collision detection problem using get_slider_count

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

So here’s a bit of background on what’s going on:

I’ve been using this engine for two days, and only when I have spare time when I’m not working or cleaning house or what-have-you. Time is limited. I ran through HeartBeast’s tutorial on YouTube and ended up with a very simplistic platforming engine which I have been attempting to use to learn how to use Godot correctly. Learning is 90% experimentation and 10% repetition, as I sometimes say.

So my experiment today has me in a bit of a funk. I’m attempting to detect specific collisions and set up a cliff grapple. You know, where the character is dangling off the end by his/her hands? I attempted to utilize the instructions found here.

My problem is that these instructions don’t seem to work. Nothing happens. There is no output to the console. I attempted to use print statements to isolate the problem, and I seem to have located it. Here is a look at what I’ve been doing:

extends KinematicBody2D

const UP = Vector2(0,-1);
var motion = Vector2();
export var maxSpeed = 200;
export var gravity = 5;
export var jumpForce = 400;
export var acceleration = 50;
export var frictionWeight = 0.2;
export var airFrictionWeight = 0.05;
var friction = false;
func _physics_process(delta):
	motion.y += gravity;
	if Input.is_action_pressed("ui_right"):
		motion.x = min(motion.x+acceleration, maxSpeed);
		$Sprite.flip_h = false;
	elif Input.is_action_pressed("ui_left"):
		motion.x -= acceleration;
		motion.x = max(motion.x-acceleration, -maxSpeed);
		$Sprite.flip_h = true;
		motion.x = lerp(motion.x, 0, frictionWeight);
		friction = true;
	if is_on_floor():
		if Input.is_action_just_pressed("ui_select"):
			motion.y = -jumpForce;
		if friction == true:
			lerp(motion.x, 0, frictionWeight);
		if motion.y < 0:
		if friction == true:
			lerp(motion.x, 0, airFrictionWeight);	
	motion = move_and_slide(motion,UP);
	print (get_slide_count());
	for i in range(0,get_slide_count() - 1):
		var collision = get_slide_collision(i)

Pretty much all of that is straight from the tutorial and from the aforementioned QA post. My other experiments are from different areas of the project and are irrelevant to what’s happening here. I seem to have isolated the problem: print(get_slide_count()) returns a value of 0, which means that the engine isn’t detecting the collisions. At all. So if that’s the problem, what’s the cause? And what is the solution?

In theory, if I could detect when the player is against the collider of tile “0” (the topmost left corner), I could then trigger a flag which would disable movement until the jump button is pressed. I could set the sprite to the grapple sprite until the player is once again in motion and the experiment would be 50% complete (until I repeat these steps on the opposite corner). I just need to figure out why the collisions are not being detected.

If it helps, by the way, the nodes for the tiles are layed out like so:

JungleDirtTiles (Node) => Sprite => StaticBody2D => CollisionShape2D (rectangle)

Any help that can be given would be greatly appreciated.

Thank you!

Still hoping for some kind of help, because I’m stumped. At this point, I’ve even tried adding an Area2D to the relevant tiles to try and trigger collisions that way, but when I use the DEBUG menu to show collision boundaries, the Area2D doesn’t even show up.

This is maddening.

SawmillTurtle | 2020-02-15 22:29