# Speed of a Sine

Get help using Construct 2

### » Wed Apr 22, 2015 12:53 pm

I have a sprite with a sine behavior; Period: 5, Magnitude: 100. How do I measure its speed?
B
18
S
6
Posts: 33
Reputation: 1,254

### » Wed Apr 22, 2015 1:40 pm

The linear speed is variable, I guess you can calculate it by checking the position at several time intervals.

You initialize the oldXposition of the sprite.
Every S seconds you get the newXposition of the sprite, calculate the speed with ABS(newXposition-oldXposition) and just afterwards update the oldXposition with the newXposition value.

This will give you the speed in px per S seconds you have defined. If the S value is too small, reaching the per tick system limit, I guess that it will give bad readings. The speed of the sine goes from 0 in the edges to the max speed when passing the initial point.
B
7
S
2
Posts: 15
Reputation: 614

### » Thu Apr 23, 2015 8:12 am

Will this method give me an accurate number? It seems that sine behavior does not have one constant speed as it is always changing.

There has to be a way. Maybe there is a way to measure how many pixels it is moving every tick?
B
18
S
6
Posts: 33
Reputation: 1,254

### » Thu Apr 23, 2015 8:15 am

Change the every x seconds in the above answer to every tick and....
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775