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

Get help using Construct 2

Post » Wed Mar 09, 2016 2:24 pm

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

Image
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:

Image

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:

Image

How I make the player attach to the yellow circle:

Image

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:

Image

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:

Image

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?
Last edited by felipenanni on Thu Mar 10, 2016 2:38 pm, edited 1 time in total.
B
4
Posts: 3
Reputation: 206

Post » Wed Mar 09, 2016 8:31 pm

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: add-catapult-to-angry-birds_t85242?start=10
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Wed Mar 09, 2016 8:44 pm

Thanks, gumshoe2029! I'll check it when I get back from school and report here! :)
B
4
Posts: 3
Reputation: 206

Post » Wed Mar 09, 2016 8:50 pm

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)
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762

Post » Thu Mar 10, 2016 2:36 pm

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!

Image

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! :D

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

Image

Thanks a lot to both of you for helping me!
B
4
Posts: 3
Reputation: 206


Return to How do I....?

Who is online

Users browsing this forum: lolsuperscratch, RobertMKD, tarek2 and 9 guests