How do I set rotate speed to bullet speed of another object

0 favourites
  • 6 posts
From the Asset Store
Simple resize and rotate events for any sprite, quick and easy event sheet that you can use for your own projects.
  • I have a cart with two wheels. The cart has bullet behavior and the wheels have rotate. I'd like to have the wheels rotate the same speed as the cart moves.

    The cart only moves on the X axis. I don't want to use physics here, the cart only has to move about 200 pixels.

  • To set the speed of one object to another, as your title suggests, you can simply do set Object1 speed to Object2.speed.

    Not sure if that applies to your wheels though. But similar thing can be done but not sure how you have it setup. May be rotate speed or an animation but same principle works.

  • To set the speed of one object to another, as your title suggests, you can simply do set Object1 speed to Object2.speed.

    Not sure if that applies to your wheels though. But similar thing can be done but not sure how you have it setup. May be rotate speed or an animation but same principle works.

    Thanks for the reply, but i'm trying to get the wheelsto rotate at the same speed as the cart moves. Yeah, i have to change the title.

    Right now i have Cart with bullet behavior and only speed set.

    The 2 wheels have rotate behavior. Like i said, they only travel a short distance but the wheels look off a bit from the speed of the cart.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can figure it out but it will require a little math (surprise surprise, right?)

    In one wheel revolution the cart should travel the distance of the circumference of the wheel. So in the time the wheel rotates once the cart should move the circumference. So, cart speed/second = rotations/second * circumference.

    Therefore set your rotate speed to Cart Speed / circumference

    ...I believe this is correct but its kind of all off the top of my head, and maybe there is a Construct feature/expression that can make it simpler for you but I'm not aware

  • First things first : Units.

    In c2, speed is usually expressed in pixels/tick or pixels/seconds. Two different units.

    The speed (expression) of bullet behavior (look in expressions panel) is expressed as pixels/second. There is a very important thing that comes with that knowledge. Wherever you see 'pixels/second' it means that this speed is already frame-independent.

    So what ever solution, it must be frame-independent too. Else, you could have it right on your computer, but on another device it will be totally wrong.

    If you gonna rotate it like ...

    Every tick > rotate 1 degree clockwise

    You will have to frame correct it like

    Every tick > rotate 60 * dt degrees clockwise

    Now, if we take a look at the Rotate behavior, its speed (expression) is also expressed as pixels/second. Meaning, the Rotate behavior is also already frame-independent. Well, why make it difficult, lets use it.

    Ok so .. Speed is distance/time.

    The distance a circle makes in 1 rotation = 2*R*pi.

    R in this is the radius. 2*R is the width of the wheel.

    So it is 'width of the wheel' * pi.

    The same speed would be when car.bullet.speed (pixels/second) = Wheel.width * pi (pixels/second)

    But, we need this in degrees/second

    1 degree = a distance = Wheel.width * pi / 360 (pixels)

    so

    1 / (Wheel.width * pi / 360) degrees = 1 pixel

    or

    360 / (Wheel.width * pi) degrees = 1 pixel

    For any pixel

    x * (360 / (Wheel.width * pi)) degrees = x * 1 pixel

    Say x be the car.bullet.speed

    car.bullet.speed * (360 / (Wheel.width * pi)) degrees = car.bullet.speed * 1 pixel

    So .. to have the same speed, you give the rotation behavior this speed :

    (car.bullet.speed * 360) / (Wheel.width * pi)

    I am not that big of a math brain, hope its right, so from the head.

  • I am not that big of a math brain, hope its right, so from the head.

    99Instances2Go WOW! My brain hasn't hurt that much since sophomore chem class.

    It appears your a bigger math brain than I.

    Thank you so much for this...it works perfect.

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