4.3
So I have been making platformer lately and I like just need spikes before I upgrade the map does anyone know how to make spikes?
4.3
So I have been making platformer lately and I like just need spikes before I upgrade the map does anyone know how to make spikes?
What do you have so far? What do your spikes need to do?
Using an Area2D’s body_entered
signal you can call a function to deal damage to your player/CharacterBody2D.
Cool, you can store the starting position
on _ready()
and re-set that when the player is spiked.
extends CharacterBody2D
var starting_position: Vector2
func _ready() -> void:
starting_position = position
func die() -> void:
position = starting_position
The spike will only have to call body.die()
on applicable player collisions.
So this is the code for it???
A sample for your player yes. Your spikes will need an Area2D as I’ve described here
ok do you recommend any tutorials that is up to date?
Not much else too it, if you are having trouble connecting signals through the editor you can check this tutorial from the official docs
This spike script could be this
extends Area2D
func _on_body_entered(body: Node2D) -> void:
if body.name == "Player":
body.die()
There are many solutions to this problem which you can find multiple tutorials on youtube for, here is one I think is nice to implement and is quite simple:
To setup your character for taking damage/dying there are 2 steps:
Now, create a spike scene that can interact with the player:
And that’s it! Now, you can write whatever code you want in the “die” function so the player does an animation and then emits a signal to the level to restart, or just change it’s position to the start of the level or whatever you want to happen.
But the thing is that I’m not using 2 scenes I have a camera that follows the player out of the rendering zone so that’s how my game works! I will send you a picture soon of my game setup