Hero Passing through Hazards

Godot Version



I have a hero character and tileset that is working and am now trying to work on creating hazards as I want to implement a health bar. The hazard I am trying to implement is a spike, all it does at the moment is print that the “hero” has hit the spike.

The thing is I do not want the “hero” going through the entire spike ala:

Is there any way of structuring the collision between the 2 objects so that only the tip of the spike is showing at the hero’s feet, indicating a collision and loss of health. When it comes to collisions, I only have the first Brackey’s Godot tutorial as a guide :grimacing:.

As always if anyone can help or even point me to a Youtube vid that would help here is a big thankyou in advance.


i forgot how he did the spike thingy, if the spike is part of the tilemap’s tileset’s tile, then you can easily set up physics layer that let you step on it.
if it doesnt, then you will need a StaticBody2D with collision shape, then your hero can step on it.

1 Like

There was no spike type elements in the tilemap so I had to download a spritesheet and create an Animated sprite with just one animation - I didn’t know what elase to do. So, I’ll look into the StaticBody2D and collisions right away.


iirc, the hazard is area2d type parent node with script to know if the player body entered it. yes so you can just add static body 2d as the child of this type of node and has its collision shape to make it able to step on it

Yep, staticbody2D seemed to do the trick :grin:.

Thankyou greatly!

1 Like

I just found a problem! The “hero” wasn’t going through the spike as I wanted, good, but, it wasn’t registering a collision.

I was using the code:

func _on_body_entered(body):
if body.is_in_group(“hero”):
print(“…on Spike”);

An easy fix I thought the “hero” is in Layer2 as per the tut. So I set the collision Mask to “2” and the spikes fell of the platform they were sitting on. So I am a little lost as to what to do?

Can anyone help?

you will want the area2d to be larger in size than the collision of static body 2d, else it wont wont trigger the body enter on area2d because the static body 2d colision shape size is exact same of the area2d
other way is just try to get the collision detection from staticbody2d’s collision with the player, so dont need the area2d colision body entered

This is what I have done thus far with the spike and believe me it’s not much:

Does this tell you anything that I am doing wrong? Because I don’t see it - collisions in Unity was always a weak area for me.

In the meantime, I will try and generate a collision between the player and the spike and see it that accomplishes anything.

where the area2d? also is that a rigidbody2d?
the area2d to detect player enter and child with static body2d should do the job fine
static body 2d will be just there to make the spike step-able. Area2d will be used to detect player body entered
you can even make a transparent tile that has Physics Layer in it then draw this tile to where the spike at so it looks like it’s step-able

1 Like

I did realize that, but, I don’t have the foggiest Idea how to add anything to the tileset or even adding a second tileset which is why I am leaving it alone. I have never used a tileset before because I never went for 2D when I was in Unity. Still have a lot to learn in that regard. Although there is an empty tile I could possible use!

I thought you wanted me to create a RigidBody2D, but, it appears that I read what I wanted to read - which is quite embarrassing.

yeah dont, staticbody2d is more like it, unless you want to make it move
also a game like this shouldnt even need until rigidbody2d to be made, there’s a built-in godot node that actually help developer to make their easy 2d game. it’s characterbody2d. it has built-in move_and_slide() that mimic what rigidbody2d can do (move and slide with collision) without needing hard physics simulation of rigidbody2d.

Thanks for sticking with me it was greatly appreciated.

Even with this quick interaction I did learn some important things.

Thankyou and Regards.