How do you make an object fall when another disappears? In my game, I want an arrow to fall when the rope disappears after being touched by my sprite.
Hi @ItsFoxy87YT!
Here is what you’ll need to do before you program how to do this:
- Create 2 objects. The object that will be falling, and one object that will look as if it’s holding that object
- Put a Physics behavior on the object that is going to be falling
- Add a join behavior to the object that is going to be falling. Join it to the object that looks like it’s holding the object that will fall
The gold blob will be falling, the rectangle looks like it’s holding the blob.
The blob has the join and physics behaviors.
Now for the code:
This will allow the blob to fall!
By the way: you do not have to show the line when you use the join behavior (the blue line above). I just did that to show you what is being joined.
To explain the code just in case: when the game starts, the physics behavior will be turned off on the blob. This makes sure that the game is certain that the physics behavior is off at the beginning.
When the rectangle is tapped, the blobs physics is turned on and is unjoins the rectangle, causing the blob to just fall.
Hope this makes sense!
Ok thank you! A quick question is can you do the same if another object touches the rope or whatever?
You should be able to, yes
As long as things unjoin, things should work. I would mainly use the join behavior on the blob because if you use it on the rectangle, it can cause issues.
I can’t select an object for some reason after it’s been joined
Hi! I have another question. Can I repeat using code as well? I want my person to repetitively lose health after touching a fire. I’ve already got code to subtract health once and to turn on a fire particle effect, but I want to repeat the lose health code without continuously making that code over and over again. Is there a way to do this?
You could add a variable that will last for a few seconds (or more if you’d like)
So lf you touch the particle affect, have the variable be set to something (like 1 or 2)
And every 5 seconds, the variable can be set back to 0 to stop losing health
Just make sure you say that when the variable is at 1 that the player loses health
And how do you do the wait 5 sec thing?
Sorry, I’m new.
Okay, I kinda lost track. Let me start over.
So the first couple of questions was for another game which I figured out.
So for my other game, I want this guy and this campfire.
And I want it so that when the guy touches the fire, the life meter will slowly deplete and each time the life meter goes down, it will play the sound “hit3”. I already have the fire particle effect (which will activate after touching the fire) and the control pad (which will speed up after touching the fire.) but I’m really stuck on the code.
Okay, from your first message it sounded like you wanted a “buff” that caused the player to lose health after touching the fire- like In a lot of games.
My apologies.
Here’s what you should do:
The blob in the image is the fire for this example
When the player touches the fire, it will lose 0.05% of its health continuously until the player quits touching it.
While it he touches it, it will play the hit3 sound effect continuously as well until the player quits touching the fire
Can you repeat that code? The challenge of the game is to not touch the fire or else your health will deplete over time until you get to 0 health and lose.
Yes! That code can be repeated!
Thanks a lot Dravins for this, was looking for some similar stuff way out.
Regards,
Cisa Smith