thats weird, ill send it again
Ok I sent it again
Part C3-17-2021_14-39-43.wick (79.9 KB)
Unfortunately I’m not the best at coding so maybe @pumpkinhead @awc95014 or @Jovanny could help?
Okay thank you
Well i can break this down into 2 steps for you if you want to do this in the future.
A way to detect when a coin is hit is to use hit triggers. Here are some steps to use them.
- Make Your objects clips and name them for example a coin could be named “coin” and a plane could be “player”
- Add code to your plane object in an Update Script, you can add one by clicking “add script” and going under timeline, then add the following code
if (this.hits(coin)) {
project.score += 1;
};
- Create a text box, put in some placeholder text, and name it scoreCount. This hooks it up to the code below.
- Next, in the code for the frame (Box with all the content at the bottom, make another update script with this code.
scoreCount.setText("Score: " + project.score)
This sets the counter to our score value whenever it goes up.
And theoretically you should be done.
If this doesn’t work for you, I got most of this from Luca’s tutorial. Watch it here!
Hi @evilmeap12, welcome to our forums:
Here is a tutorial for collectibles, you could do a similar thing:
Collectibles Tutorial
For the health bar, you could also do something similar to this, but instead of hitting the button, you will apply the logic when you collide with the jerry cans.
Health Bar Tutorial
Hope this helps.
thank you I will try it when I get home
Thank you, I got the score working now :D
I do like the Bar but im having a hard time because of collision. When the pig hits the plane I want to plane to lose health. the collision is what is hard for me, im not sure what to do.
under plane update script tab write the following:
if(this.hits(pig)) {
// lose health
}
Replace the comment by the logic for losing health.
for this script here, do I put it under the plane in the default tab?
this.energy = 100;
this.max = 100;
this.takeDamage = function(damage)
{
this.energy -= damage;
if(this.energy <= 0){
this.energy = 0;
}
this.energyBar.scaleX = this.energy/this.max;
this.play();
}
Yes, you can do that… (well, no… unless you have the energyBar inside the plane clip which I don’t think so…)
oh thats true, I dont have it in there
Can I do the health with text, so like
Health: 100
so it works like a score but opposite
every time the player gets hit it loses 25 health or something?
Of course, It is your app, you do with it as you please.
ok
Ill name the text “healthCounter”
and for the code do I put
healthCounter.setText("Health: " + project.health)
would that be right?
That should work as long as you are storing the airplane energy at project.health
Alright thank you.
Sorry one more question for the pig would I put
if (typeof player !== ‘undefined’){
if (this.hitTest(player))
project.health -= 25;
}
healthCounter.setText("Health: " + project.health)
Do you plan to remove the player at some point? I’m not sure why you are evaluating player against undefined…