|
|
|
|
Reply From: |
M. Alkotob |
You can create an invisible Sprite checkpoint node (or visible if you want) and place it as a checkpoint in the level.
Then, when you want to move the player, try:
func onEnemybodyenter( body ):
if body.getname() == "Player":
body.kill(get_node("checkpoint"))
and in player:
func kill(checkpoint):
setpos(checkpoint.get_pos())
If you want to have multiple checkpoints, then instead of passing getnode(“checkpoint”), you can pass a node LatestCheckpoint, which is changed every time a player passes through a new area.
You can create a large collision rectangle for the checkpoint (as a child) to see if a player passed the area. Make it tall vertically so he wouldn’t jump over it by accident.
P.S. Let me know what happens.
It worked!
Minor minor thing was that setpos in the player needed to be set_pos and I had to change the funtion to “_hurt” and replace all the kills for those enemies with hurt as the function had already been used.
Thanks so much!
holhow | 2017-03-18 15:03
Ah apologies about setpos(), but the website converts underscores to italics so I removed it
(Next time I’ll add code tags)
Good luck with your game!
(I’m working on one too and I just like to take a break and solve other people’s bugs hehe)
M. Alkotob | 2017-03-18 17:25
Oh cool! Good luck with it!
Would you know how to make the player bounce [bouncy?] when it contacts one specific static body? I want the player to bounce off the floor in one part of the game but not in others.
holhow | 2017-03-18 22:30
To make the player bounce, this is similar to what I use:
if(not is_bouncing):
is_bouncing = true
set_linear_velocity(Vector2(-get_linear_velocity().x/2, -get_linear_velocity().y/2 ))
The if() statement is necessary since without it the velocity is divided every frame that you touch the ground (instead of only once).
Instead of dividing by 2, you can try other numbers like 1.5 or 3. Using 2 makes it realistic and using 1 will make him bounce with the same speed (which can be fun).
Note that this will only let you bounce once, or else you will want to reset the boolean to false elsewhere in the code.
In order to reset the boolean, you can try this function in the player:
func reset_bounce():
for collider in get_colliding_bodies():
if(collider.get_name() == 'bouncy_platform' and is_bouncing):
return
is_bouncing = false
M. Alkotob | 2017-03-19 06:18
hey, i’m sorry, i’m super new to godot but it’s running the error that it can’t find is_bouncing and so it won’t run - do you know what that means?
holhow | 2017-03-19 13:03
You need to put this line at the top of the script:
var is_bouncing = false
M. Alkotob | 2017-03-19 14:21
hey, sorry again, feel free to not reply but it’s also saying that set _ linear _ velocity is an nonexistent function and I’ve tried adding constants and variables but nothings working.
holhow | 2017-03-19 15:49
Don’t use a Sprite. Position2D nodes were made specifically for things like this.
timoschwarzer | 2017-03-19 19:50
You’re right Position2D would do.
It’s just me, but I like to use accurate replicas of my character so I can have a sense of where he will be located after respawn.
M. Alkotob | 2017-03-19 19:52
Don’t even need a node other than area unless you need more visual debug than a shape.
And shape could be a line shape if your game is a strict sidescroll, that way the player won’t miss the checkpoint no matter how much tries to cheat
please show the whole script
christianbegg2 | 2018-07-30 18:35