How to increase force based on duration of mouse press?

chongyunxiang

  • Posts: 216
I'm trying to increase the amount of force based on the duration of the mouse pressed.
I can't get the behavior to shoot after I've added in these few events. Initially it was simple :When Shoot happens, create Bullet...Push last created actor...etc. It was working, but once I've added in the setShootTimer and the other blocks, it doesn't shoot out bullets anymore.

How do I solve this or is there a better way of increasing the pushing force based on duration?

Thanks!

tigerteeth

  • Posts: 734
I would do something like
IF mouse is down
increment force by 1

IF mouse was released
Create bullet
Push last actor by (force)/100
Set force to 0

chongyunxiang

  • Posts: 216
I tried, but it's still not shooting. Can't seem to figure out why I can't shoot.

JeffreyDriver

  • *
  • Posts: 2151
On your shoot behaviour, try removing the  'if' and 'otherwise' if statements, and put them into an input behaviour instead.

On Mouse Release
If ShootTimer <1
...
otherwise if ShootTimer >=1
...
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Rimrook

  • Posts: 251
In a Do Every event for 0.1 or 0.05 seconds, put an if statement to check if the mouse is down. If it is, increase by 1. If not and the value is higher than zero, run the next part of your behavior.  Hope that helps a little.

chongyunxiang

  • Posts: 216
I've tried, but I still can't get it to create any bullets. I've attached the initial one that allows me to create bullets. But when I added in the ShootTimer attribute, it doesn't create any bullets.

Thanks for the help!

KramerGames

  • Posts: 405
just guessing but I could imagine that it checks exactly every second if the mouse is being released in that moment. You could change it to "if mouse is not down". Anyhow I think tigerteeth suggested a simple and very effective solution (that allows for a lot of fine tuning), try it out.
Parasites United  (Idle Parasite Game)

chongyunxiang

  • Posts: 216
I tried Tigerteeth method as well. I too find it a much simpler method, but it didn't create any bullets. I think I'll redo this shooting behavior.

Rimrook

  • Posts: 251
When I can I will look into s simple behavior for this.
I have a charge up and blast system on my current game so maybe I can pack it up and share it.

alkanadi

  • Posts: 17
But when I added in the ShootTimer attribute, it doesn't create any bullets.

You have a 'if' statement and an 'otherwise if' statement. Can you make a third option, which would be an 'otherwise'.  Have it print something arbitrary to the screen. This will help us troubleshoot.

There seems to be something wrong with 'mouse released' or 'shootTimer'.  Things to try:
- At the beginning of the shooting, say shootTimer = 0.
- Make sure that shootTimer is an integer and the default value is 0.

KramerGames

  • Posts: 405
I tried Tigerteeth method as well. I too find it a much simpler method, but it didn't create any bullets. I think I'll redo this shooting behavior.

In case you saved it, would be nice if you could post a screenshot of it. Did you make the first one "when mouse is down" an update event and the second one "when mouse is released" an input event?
Parasites United  (Idle Parasite Game)

chongyunxiang

  • Posts: 216
alkanadi, i've added and otherwise statement and everytime I click, the otherwise statement runs. Means my If and Otherwise If statements are not working.

I've attached a screenshot containing 3 Shoot events that I'm trying out. The 1st shoot event works. The 2nd and 3rd doesn't create the bullet. I've only meddled with the Shoot behavior.

KramerGames, I didn't save what I did previously, but the screenshot shows what I've tried.

chongyunxiang

  • Posts: 216
I can't seem to figure out why the bullet is not creating, but I've also managed to make the rotation counter as well as a multiplier when it goes above a certain number of rotation. If any of you would like to see how I did the rotation and rotation point multiplier, let me know.

Now I've also faced another problem besides the Press and Hold. I'm trying to award the players if they use the walls to bounce the bullet and hit the target. It's able to increase the points, but it doesn't work properly. When the bullet(rubber material) hits the wall twice, it executes the If statement to increase the score by 100, which is not supposed to. The If statement to award the player if they can ricochet the bullet off the wall, is when the HitWall and HitEnemy is both True.

I've disabled the Trigger event Hit as I've removed the Hit behavior(it was just something that I was trying quite sometime ago.)

CmdrWhitey13

  • Posts: 503
I would do something like
IF mouse is down
increment force by 1

IF mouse was released
Create bullet
Push last actor by (force)/100
Set force to 0

This method works. Ive just set something up and works awesome. See attached screenshot and modify behavior  as needed.
Hope it helps.

chongyunxiang

  • Posts: 216
Hi CmdrWhitey13, everything works if its on an Always event, but I'm trying to put it in a behavior that can be disabled.

Like:
When mouse is pressed, do after 0.5s, set Playing to True, trigger Shoot event in behavior Shoot.

When Shoot happens, increment of Force by 1. If mouse was released, do after 0.2s, create bullet....Set Force to 0, SetPlaying to False.

but it's not working. I want to control the time interval players can shoot and not spam bullets. Not sure if this is the right method. pretty sure it's wrong since it's not working! Haha!