How do I make object change speeds.

Just started using Construct 2? Post your questions here

Post » Thu Mar 06, 2014 11:08 pm

Hello all. I am sorry to have to come here to ask but I can't find the answer and I have tried several different methods in games and can't get the object to change speeds.

I am trying to create a game for my daughter to play that she asked me to put together. It's a simple character race game and if player hits an object it changes speeds to go faster. So it's a power up basically. Here is what I have tried. In the events tab I placed it as if player -> on collision with power up -> player >under the set acceleration to lets say 1000 (I also have it so that when the player hits the power up it is destroyed)

So what I am trying to figure out is if I have to have the max speed on the player it self at 1000 or if I have to have it at lets say 200 and when it hits the power up it boosts up to 1000 but when I tried that it stays at a consistent speed.

I hope it's ok that I added a couple of photo's to explain what I described but they are below.

Thanks in advance for any help given.
You do not have the required permissions to view the files attached to this post.
B
3
Posts: 6
Reputation: 239

Post » Thu Mar 06, 2014 11:17 pm

You'll want to bump up the Max Speed instead of the Acceleration.
B
6
S
2
G
2
Posts: 16
Reputation: 1,153

Post » Thu Mar 06, 2014 11:22 pm

Thank you for the quick reply. Is there anyway that you know of to limit the duration of the power of for lets say 3 seconds. I will try to figure it out in the mean time.
B
3
Posts: 6
Reputation: 239

Post » Fri Mar 07, 2014 12:10 am

Code: Select all
Global variable speedPowerTimer = -1


System->on every 1 second
       Compare variable speedPowerTimer > 0: set variable speedPowerTimer = speedPowerTimer - 1
       Compare variable speedPowerTimer = 0: set Max Speed to 300 : set variable speedPowerTimer = speedPowerTimer - 1



Then add one of the following to the collision event

This one will make it so the duration is always 3 seconds whether or not you get 2 power-ups in a row
Set variable speedPowerTimer = 3

This one will make it so that the power-ups stack
Set variable speedPowerTimer = speedPowerTimer + 4

The reason +4 is used is to move it up to 3 from -1.
The reason -1 was used was to ensure that the speed wasn't unnecessarily reset every second.

One side effect is that when stacking 2 in a row, instead of going for 6 seconds, the speed is increased for 7 seconds.
The workarounds are either a minor performance hit by removing the subtraction from the check to see if speedPowerTimer is equal to zero and setting the value initially to 0, or to add sub events on the collision to check the value of speedPowerTimer, and setting it to 3 if it is -1, else set it to speedPowerTimer + 3.


Another optimization in the future to look at would be using an instance variable on your player so that you could have multiple players or ai using powerups.

Anyway, I hope I didn't ramble on for too long. I tried looking for a tutorial to help out, but they were primarily concerened with on screen timers. Good luck with your game.
B
6
S
2
G
2
Posts: 16
Reputation: 1,153

Post » Fri Mar 07, 2014 8:19 am

All in one event

Global (or instance) variable speedPowerTimer = 0

Every Tick
Set speedPowerTimer to clamp(speedPowerTimer - (60*dt), 0 , 99)
Set Speed to speedPowerTimer > 0 ? 400 : 200

When you get the power-up, you can set speedPowerTimer to X seconds

PS: The expression "speedPowerTimer > 0 ? 400 : 200" is a conditional expression.
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Fri Mar 07, 2014 5:46 pm

7Soul wrote:All in one event

Global (or instance) variable speedPowerTimer = 0

Every Tick
Set speedPowerTimer to clamp(speedPowerTimer - (60*dt), 0 , 99)
Set Speed to speedPowerTimer > 0 ? 400 : 200

When you get the power-up, you can set speedPowerTimer to X seconds

PS: The expression "speedPowerTimer > 0 ? 400 : 200" is a conditional expression.


Fantastic @7Soul! Go with this @moneybiz.
B
6
S
2
G
2
Posts: 16
Reputation: 1,153


Post » Tue Mar 11, 2014 5:13 am

Just wanted to update on what I found out. Since I am not in any way a programmer most of what you all said pretty much went over my head and I know that makes me sound like a noob but I do thank you all for trying to answer my question but I did keep looking and found a simple but effective way to fix the problem I think. I works so far and I will keep testing it but I figured I would post it here to show what I did to resolve the issue for now at least. I am writing this for those who like me know nothing about programming and maybe for those who do know programming this may help later on if they see someone else with a problem like this. I will keep testing it out but for now it seems to work.

Here is how it went for me.

player -> On collision with another object (Chose Power Up) -> (Add Action) Player -> (under 8direction) set max speed (I chose 1000)
->(Add Action)Power Up -> (under misc.) destroy
->(Add Action) System -> (Under Time) Wait (I chose 3 seconds)
->(Add Action)Player -> (Under 8direction) set max speed (I chose 200)
You do not have the required permissions to view the files attached to this post.
B
3
Posts: 6
Reputation: 239

Post » Wed Mar 12, 2014 3:35 pm

I am happy that you found the way moneybiz. That's easy
B
257
S
42
G
15
Posts: 1,991
Reputation: 41,411


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests