[SOLVED] Make the player rotate&jump from a horizontal bar?

0 favourites
  • 5 posts
From the Asset Store
a full game example, menu system, with the first level and a boss, to create a horizontal shooter
  • Hello!

    I'm trying to make a 2D runner / gymnastics game, where the player needs to use the arms (UP arrow) or the legs (DOWN arrow) to go through different equipment and score points. But I'm having trouble making the player grab the horizontal bar, rotate around it with the right angle and speed and then jump with the momentum acquired in the bar. After trying for a few days with no success, I'd like to ask for someone to help me.

    [If it's not recommended to put so many images, I can remove some of them. Also, I can provide the project file if needed.]

    I want the player to grab onto the yellow stick when he is in contact with the yellow circle and pressing UP. Then, while holding the button, he keeps rotating around it and gaining/losing speed. When the player releases the UP arrow, I want him to jump in the direction he was facing with a right speed. I already tried understanding the "How do I?" tutorials, but I couldn't make them work how I wanted.

    Here's how it is right now:

    At the moment, the player just attaches to the yellow circle's image point with the Pin behavior and just falls flat when the player releases the button.

    Here's the code for the horizontal movement:

    How I make the player attach to the yellow circle:

    First, I check for the UP arrow, then check if he's not on the floor (I changed in the code already, the image is not updated). If he's not already in the bar, the turn speed is set based on how fast he was going. After that, I check the angle between the circle and the player and position the player on the circle's image point, to pin on it. The angle_bar_to_player checks are there just to set the rotation direction of the circle. I feel there's something off with that - like if the player doesn't grab at the right angle.

    The code that runs while he is holding onto the bar:

    It just updates the the angle between the circle and the player, then it rotates and adapts the player's sprite.

    What happens when the player releases the UP arrow:

    It just Unpin's the player. I want him to jump in the direction he was going while on the bar.

    Can someone help me with this, please?

  • Ah yea, the physics engine doesn't model mass-based intertia, so you will have to mimic it with events.

    Look at using Physics>Apply Force(x,y) or Apply Impulse at Angle like the example in this post:

  • Thanks, gumshoe2029! I'll check it when I get back from school and report here!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When you release you need to convert the angular velocity to a linear one. The equation for that is:

    linear = radius*angular

    where angular is in radians.

    Here's a complete calculation:

    radius = distance(bar_contact_zone.x, bar_contact_zone.y, player.x, player.y)

    angle_of_motion = angle(bar_contact_zone.x, bar_contact_zone.y, player.x, player.y) +bar_rotation*90

    speed = radius*bar_turn_speed*pi/180

    velocityX = speed*cos(angle_of_motion)

    velocityY = speed*sin(angle_of_motion)

  • Hey guys!

    I saw that gumshoe2029's examples used Physics, so I'd have to change a lot of things in the project (well, I think I'd have to change, because I never used Physics). Before trying that, I used R0J0hound calculations and it worked!

    I still need to tweak the values a little and also the camera, but he's jumping like I want to now!!! Oh, I'm so happy!

    Here's the code for when the player releases the bar:

    Thanks a lot to both of you for helping me!

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