How do I get speed from physics

Get help using Construct 2

Post » Tue Jun 30, 2015 4:53 pm

Hello fellas!

I don't want to be considered as a spammer, but unfortunately the information I found on the forums was to less and sometimes incomplete, that's why I bring the topic again and I hope we get it right.

My case is that I have a physics ball which I want to animate its movement. It has already several frames to make the rolling illusion.

The thing is that I would like to get the speed to move the frames, thus getting a real effect.

I already tried a few codes without any success:

distance(0,0,sprite.physics.velocityX,sprite.physics.velocityY) to get the speed, and angle (0,0,sprite.physics.velocityX,sprite.physics.velocityY) to get the angle of the shot.

I also tried to change from physics to bullet and the results where even crazier than before.

I think this should be achievable, and if we find a solution it will be a great input since this is an important way to simulate some kind of 3D in the Construct's 2D environment.

Thanks in advance!
B
4
S
1
Posts: 34
Reputation: 416

Post » Tue Jun 30, 2015 6:04 pm

So just to clarify you have an animation of a 3d ball rolling and you want it to be syncronized with the motion of the ball?

In the simple case of having an animation of the ball rolling to the right you can set the angle to be the same as the angle of motion as you have above.

The second thing to do is correlate the animation speed with the speed of the object's motion.
So depending on the number of frames you can find the time for a full rotation with:
Time_for_full_rotation=num_frames/animation_speed
So we can the find angular speed with:
Time_for_full_rotation*angular_speed=360

Which then solves to:
Angular_speed=Animation_speed*360/num_frames

You can then relate linear speed to rotations with:
Speed=radius*anglular_speed*pi/180

Then combining the two:
Speed=radius*animation_speed*2*pi/num_frames

And solving for animation speed we get our formula:
Animation speed=Speed*num_frames/(radius*2*pi)

Speed can be calculated as you have.
Radius is half the width of the ball.
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

Post » Tue Jun 30, 2015 6:45 pm

Maths (yes I'm British, and this is how we say it) is such fun :)

Thanks for the formula, R0J0hound.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
137
S
31
G
87
Posts: 5,548
Reputation: 60,440

Post » Thu Jul 02, 2015 10:52 am

@R0J0hound thanks for your answer, great that there's a way to achieve this, though, for me looks a bit abstract due my knowledge on C2 and mathematics (tried a couple of days trying to figure out what you wrote), however, I'm always amazed by people that has this knowledge and I would like to understand these formulas.

You mentioned a horizontal angle of motion, maybe I didn't explain myself so good, but the game is like billiard, where the ball bounces against the rails, thus changing its angle. I used the angle formula, but every time when the ball stops it changes the angle of the current frame to horizontal.

Are these formulas still working for what I need? By the way, I'm using 40 frames in my animation.

Much appreciated.
B
4
S
1
Posts: 34
Reputation: 416

Post » Thu Jul 02, 2015 8:12 pm

Yes, the formulas you used for getting the speed and angle of motion, and the last equation in my post for the animation speed.

To fix the angle to point to the right when stopped, only set the angle when the speed is greater than zero.
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

Post » Fri Jul 03, 2015 10:49 am

Thanks a lot R0J0, I look forward to give it a shot.

Though, I don't want to fix the angle to the right when the ball stops, I'd like to keep the same angle it has before stopping. Maybe the same principle but in reverse mode?
B
4
S
1
Posts: 34
Reputation: 416

Post » Fri Jul 03, 2015 5:11 pm

By "fix" I meant fixing the issue of the angle going to right when the speed is zero.
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

Post » Mon Jul 06, 2015 5:04 pm

Hi R0J0, after a few days I could solve the formulas and worked like charm!

Thanks so much for the input, I'm pretty sure this information will be helpful to future constructors.

Cheers!
B
4
S
1
Posts: 34
Reputation: 416


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests