How do I get speed from physics

0 favourites
  • 8 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • 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!

  • 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.

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

    Thanks for the formula, R0J0hound.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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?

  • By "fix" I meant fixing the issue of the angle going to right when the speed is zero.

  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)