How do I make object change speeds.

0 favourites
• 9 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
• 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'll want to bump up the Max Speed instead of the Acceleration.

• 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.

• ``````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

[/code:yw4cq77q]

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.``````
• 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.

• 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

https://www.scirra.com/tutorials/806/instance-variable

https://www.scirra.com/tutorials/823/creating-function

• 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)

• Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I am happy that you found the way moneybiz. That's easy

• 9 posts