How do I increase a number with 1 formula?

Just started using Construct 2? Post your questions here

Post » Mon Feb 27, 2017 11:46 pm

For example: a sprite moves from left to right.

Code: Select all
every tick:
sprite: set x to: self.x+50


But i want the movement slightly going faster.
So I added global var num

Code: Select all
Every 1 second:
system: add 1 to num


And changed the code from above to: (added "*num")
Code: Select all
every tick:
sprite: set x to: self.x+50*num


How do I do this without adding an extra global variable?
B
28
S
6
G
7
Posts: 678
Reputation: 5,676

Post » Tue Feb 28, 2017 9:53 pm

There are two main ways:

A) If the movement coordinates (Start and End) are always the same:
Code: Select all
Set X to: Self.X + 50 + 100*[(Self.X-Start.X) / (Target.X-Start.X)]

(replace 100 by the number that should be added extra when the Sprite almost reached the target)

[(Self.X-Start.X) / (Target.X-Start.X)] calculates the movement progress of the Sprite (0 at the beginning, 1 at the end) and multiplies it with 100.
That way, the extra value gets higher, the more the Sprite has moved.

Again, this only works if the Start and End values are known and set each time.

B) Use a plugin, for example LiteTween.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Fri Mar 03, 2017 10:34 am

Thank you!
B
28
S
6
G
7
Posts: 678
Reputation: 5,676


Return to Beginner's Questions

Who is online

Users browsing this forum: AmpedRobot and 2 guests