Jump to content

Acceleration display faster and faster


pinkman
 Share

Recommended Posts

Hi, most (scaffold) on my first game I've ready so far. but on one thing I have a problem. My speedometer to show the speed, but no real benefit to the game, he will only increment beautiful.

So far I have an indication of speed. Example: Your Speed: 70 Mp / h.
When I press the start button, the speed goes from 0 to 100 in zero seconds. That's OK for the Play-Character, but only I want that runs the display logarithmic.
Example: 0 Mp/h ...., - slow up ....,  - slow ...., - faster ...., - faster ...., - faster ...., - very fast ....., - very very fast ...., Highspeed Mp/h

A short version as Gimp animation.

countup.gif

I would also like to use it for the score display. As I said: No impact on the game, just look pretty.

T
he concrete Problem: I do not know any formula for it. I tried it with a FOR loop. But the computer is too fast. The result remains 0 to 70 in zero seconds.

Can anyone help me out with a minimalist, sample script? For a beginner.

 

Thx Pinkman

Link to comment
Share on other sites

if this is purely visual, then you can just increment in the update loop like so:

create() {
    this.speedCount = 0;
    this.mySpeed = 0;
}

update() {
    this.speedCount+= 0.1;
    mySpeed = Math.round(this.calcNewSpeed();
    mySpeedText.setText(mySpeed.toString());
}

calcNewSpeed() {
    return Math.Exp(this.speedCount);
}

What this will do, is increment the speed counter by 0.1 every tick and use Math.Exp (exponential) : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp and then updates the actual speed then the text accordingly from this. What you should see, is that math.exp returns the following

0.1 = 1.01....

0.2 = 1.22...

0.3 = 1.34...

0.4 = 1.49...

0.5 = 1.68..

...

1.5 = 4.48...

What you will notice, is that as the incremented value increases, the incremented speed increases faster, hence exponential. You may want to speed up, or slow the rate at which it is sped up by simply changing the this.speedCount object in the create function :)

This should be enough to get you started :)

Link to comment
Share on other sites

5 hours ago, megmut said:

This should be enough to get you started :)

Hay megmut, yes it does!

I have it still do not get to run, something I decide wrong, but I'll manage it already.

Your obligatory built-fault and additional test order (one missing bracket) I've already discovered
:)

Thanks for your valuable help!

When the game is finished, I will present it here. Please be patient.

Best regards
Pinkman

Link to comment
Share on other sites

You can also use Phaser.Tween to tween the variable. Then in update function just set text based on current value:

create() {
    this.mySpeed = 0;
    this.add.tween(this).to({mySpeed: 100}, 1000 /* duration in ms */, Phaser.Easing.Linear.None /* easing function */, true);
}

update() {
    this.mySpeedText.text = this.mySpeed.toString();
}

 Then you can easily change easing function to produce different counter speeds (linear, parabolic, exponential, ...)

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...