RelojMRU (ClockMRU) TimerInverval initially set = 1000
The denominator in / 1000 (hardcoded number)
If you run the App and send the child to Position 0 m (the origin) and give him max velocity (65 m/s), since my width anchor is 650, for every 1000 ms (1 s) the child moves 65 m:
t = 1 --> x = 0 + 65 * 1000 / 1000 = 65 m (good)
t = 2 --> x = 65 + 65 * 2000 / 1000 = 130 m (good)
...
t = 10 --> x = 650 m (good)
It makes sense since I want the child to run from 0 m to 625 m in 10 seconds.
However, I don't know why, if I want to be more realistic since the child "jumps" from one interval to another, I do the following:
RelojMRU.TimerInterval = 1 (the interval is close to reality)
/ 1000 --> / 1 (or you can just delete the division part and only let RelojMRU.TimerInterval)
With these configuration I should also end up with a final time of t = 10 s, but instead the child finishes in less than 1 second! See image below as reference:
How can we fix this, that is, giving a realistic movement with TimerInterval=1 and also having a final time of 10 seconds? My only tools are integrated blocks and the physics formula for position.
I also have two questions:
When play button is pressed, I don't know why when the child is moving to the right (positive) and I change the Velocity red slider to a negative number (positive -> 0 -> negative) the child changes direction more quickly than doing the other way (negative -> 0 -> positive). How to fix it?
(Optional, after above questions are solved) Is there any way to improve code? I mean, I had to use 2 Clocks. Can it be done using just one? I need to be able to move Velocity red slider while the child is moving and is stopped
At least one potential problem I see is that you are using X both as the final and intermediate states. X is expected to be an integer, so if your interval ends up being a fractional value less than 1 you may get erratic behavior. Instead, you should have a variable that tracks the exact position with fractional amounts. Update the variable and then assign it to your X coordinate so the fractional pieces aren't rounded away.
A ‘sprite’ that can be placed on a Canvas, where it can react to touches and drags, interact with other sprites (Balls and other ImageSprites) and the edge of the Canvas, and move according to its property values. Its appearance is that of the image specified in its Picture property (unless its Visible property is false.
To have an ImageSprite move 10 pixels to the left every 1000 milliseconds (one second), for example, you would set the Speed property to 10 [pixels], the Interval property to 1000 [milliseconds], the Heading property to 180 [degrees], and the Enabled property to true.
You need extra equations to translate the laws of motion into the coordinate system of the Canvas.
You also need to translate the movie making concept of Frames Per Second into the Ai2 Clock setting of TimerInterval. A good human frame rate is 24 frames per second.
Is it too complex to implement? I mean, for interval of 1000 ms it seems to work fine. I tested with a cronometer and finishes in 10 seconds. But the same equation does not hold for interval of 1 ms (smoothly).
You are probably facing accumulated error and the limitations to how frequently the Clock Timer can actually fire. 20ms is probably as fast as you can get, given the time to run the code in the timer event and the overhead to start it up each cycle.
You can compensate for that, however, by calculating your X values not on how many Clock Timer cycles have fired, but instead on the elapsed Clock1.SysemTime value between when the start gun fired and the current Clock Timer cycle's calculation of Clock1.SystemTime.
That would give you as smooth a movement as your eye could see, if you don't push the Clock too hard.