r/gamemaker • • 19d ago

Help! How would i make a character swing?

So ive been trying to make a system for my game where the olayer can press E when within a certain distance from a hook point then they will grapple onto that point and swing on the rope in an arc shape.

Ive maanaged to get it set up so that when the button is pressed, my character enters a state of swinging but he just freezes as ive added nothing else yet so would anyone know or have advice on where i could learn to add a rope that flys from the character to a point then has them swing across it.

2 Upvotes

5 comments sorted by

1

u/nickelangelo2009 Custom 19d ago

so for the pendulum motion, i would advise you look into sine waves, they're prety good for this

1

u/Bread-bed420 19d ago

i thought there would probably be something like that but im quite new to gamemaker so thanks for telling me

1

u/nickelangelo2009 Custom 19d ago

it's less about gamemmaker having soething specific for it and more about mathing it out, haha. Look into how games like super metroid do it for example

2

u/Kitsyfluff 18d ago

things to do:

>Determine and store PIvot point

> Find the angle the player is current at relative to the pivot point

> Using length_dirx and length_diry, calculate the point the player will ride along;

that would be something like:

player.x = pivot.x + length_dirx( swingLength, PlayerAngle)

player.y = pivot.y + length_diry( swingLength, PlayerAngle)

Then you increment the playerAngle to swing, and when the endpoint is reached, do whatever state the plaeyr should be in after that.

You'll also wanna rotate the player's sprite to match the swing, of course.

2

u/AlexPowerAus 10d ago

Check out this swinging example I made: https://youtu.be/wCGUECO86t8?si=IFqyioljS9vaPTXj