How do I: wait time before next shot

Get help using Construct 2

Post » Wed Dec 31, 2014 12:50 am

Greetings,

at first im sorry if i didnt searched probably for the right topic i need, because i actually dont know what to search for.

so my question is: i set my fire button to the left mouse button and its working just fine, but i dont want to abuse it so i can shoot like 10 bullets in a second. How can set it up to shoot like, lets say 1 bullet every 1 second.

Thx
B
4
S
1
Posts: 25
Reputation: 402

Post » Wed Dec 31, 2014 12:54 am

While pressing left button > every 0.1s > spawn bullet

You can find in the system the expression "Every X seconds".
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Wed Dec 31, 2014 1:05 am

Thx for the fast respond, that helps alot but actually i wanted to shoot one bullet every 1 second even if i smash the mouse button, just asked the wrong way :S holding the left mousebutton to shoot isnt a option for me. Im sorry for the trouble
B
4
S
1
Posts: 25
Reputation: 402

Post » Wed Dec 31, 2014 1:09 am

You can use any trigger you want. You don't need to stick with the "While pressing left button". Also, if you want 1 shot per sec just adjust it using "Every 1 sec" > Spawn bullet
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Wed Dec 31, 2014 1:43 am

ye i know but thats the point.
its like this now:

mouse > on left button clicked -> "player" spawn "bullet" on layer 0 (image point1) // but now i can shoot as much as i want. it should take up to 1 sec before i can shoot the next bullet even with pressing the mouse shortly after. again, im so sorry for the trouble and the waste of time

maybe im to stupid to see the right trigger to use but i cant find a way to solve this problem on my own :<
B
4
S
1
Posts: 25
Reputation: 402

Post » Wed Dec 31, 2014 1:53 am

Make an instance variable called cooldown.
On left button clicked and if cooldown = 0 -> fire bullet and set cooldown to 1
If cooldown is greater then 0 -> subtract 0.5 every 0.5 seconds

You can change the numbers to suit your needs.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,986

Post » Wed Dec 31, 2014 2:18 am

ok i guess i got it so far but one more question pls, how do i trigger those 0.5 seconds ?

atm its like this for me:

1. "bullet" cooldown > 0 -> "bullet" subtract 0.5 from "cooldown"

2. "mouse" on left button clicked -> "player" start animation from beginning
"bullet" cooldown=0 "player" spawn "bullet" on layer 0 (image point1)
"bullet" set cooldown to 1

i hope there is not a "and" command like the "or" one, since i cant find it.
B
4
S
1
Posts: 25
Reputation: 402

Post » Wed Dec 31, 2014 2:22 am

You can right click in the trigger area and click on Add Another Condition. That's the same as saying "And". There is another option in there to "Make an OR block". That's the same as saying "Or" but it's a bit more complicated. You just need to use and so just add another condition along with on left button clicked.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,986

Post » Wed Dec 31, 2014 2:27 am

I give my player an instance variable that acts as a condition to shooting. On shooting, set the variable Player.TimeNextShot to time + 0.5 (or whatever). Then, as a condition to a player shoot demand, check to see if Player.TimeNextShot < time. I find it allows for easy variation in the delay time, depending on weapon in use etc.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,208
Reputation: 43,838

Post » Wed Dec 31, 2014 2:42 am

wow guys im so stupid, i didnt even tell that script what to do if the value reaches 1, exept for subtract something from it every XX seconds -.- im really really sorry for wasting all of your time
B
4
S
1
Posts: 25
Reputation: 402


Return to How do I....?

Who is online

Users browsing this forum: unicornspitfire and 65 guests