Gernade behavior

Rawr

  • Posts: 85
Well, I'd like to make the actor throw something.
I have the projectile that explodes and causes damage on impact, and also can make the actor throw it at a fix force and the direction according to which the actor is facing.

But I'd need an idea on how to adjust the force, probably according to how long to hold the key down, and the projectile is fire when you let go. Anyone know how to code that?

Thanks.

ImagineIt

  • Posts: 8
Maybe make an attribute which sets to zero unless the mouse is down? I'm new, it might not work.

Rawr

  • Posts: 85
Hmm, already got that in mind, I'm only thinking of how to make it increase by time, and how to set the force boundries. It'll probably take a bunch of "if" blocks...

Luyren

  • *
  • Posts: 2416
But I'd need an idea on how to adjust the force, probably according to how long to hold the key down, and the projectile is fire when you let go. Anyone know how to code that?

Create an attribute to hold the maximum force, an attribute to be the timer (increase when the button is down), and another for the maximum time you can hold down the button.

When the button is down, increment the timer by [step size/1000]. Then, you apply the force to your grenade with [Maximum Force]*[[Timer]*100/[Max Time]]. The percentage between the timer and the maximum time will modify the maximum force, and this will be applied to the grenade.


If the timer is bigger than the maximum time, set the timer to the maximum time. If the button is up and you're not throwing the grenade, set the timer to 0.

My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

Rawr

  • Posts: 85
Then how do you determine if the player is throwing the gernade or not?
I mean, it's both a "key released" situation...

Alexin

  • *
  • Posts: 3130
A button that is "up" is different than on that was released. A button that was released is "up", but the other way around may not be true.

Set the timer to 0.0 when the button was pressed, increment it while the button is down and throw the grenade when it was released.
"Find the fun"
alexin@stencyl.com