GameMaker [Resolved] Adjusting Angles & Angled Movement

Fulbo

Member
Hi everyone,

I wanted to ask about something that seems pretty advanced. I'm creating a platformer game, and was interested in being able to walk around an area while sticking to its surface/walls, adjusting my angle to match where I'm positioned. The following barebones mockups illustrate what I'm going for:

Angled Movement Doc 1.png .1 Angled Movement Doc 2.png .2 Angled Movement Doc 3.png .3
I'm aware trigonometry would be highly involved in this, and I'm currently trying to study up on it. In the meantime, I was wondering if anyone had any suggestions (and possibly code examples) for how I could go about tackling this.
A technique I've seen a few developers use is having sensors at both the relative left and right of the player (angle wise), and checking relatively downwards until the ground is detected. Would that be my best bet, or should I try something else?

Regards.
 

NightFrost

Member
Well, if you think of walking on a sphere, the player's angle could be directly derived from an angle calculated from its position in relation to the center of the sphere. In case of a pillow shape like that, your angle would be derived from the cardinal direction of the center, except when the absolute values both x and y positions' offset exceed a certain threshold - that is, when the ground starts to curve. When it does, your angle would be calculated from the origin point of each curve. (In other words, you still have a circle, only split into four sections.) The actual movement direction can always be derived from the player's current angle, with considerations to moving either left or right.

EDIT: also, as it might be clear from the description I've given, no collision detection is necessary, as player is simply poaitioned based on how the surface is described (radius, curve sizes).
 

Fulbo

Member
Hi NightFrost,

That's an interesting suggestion about calculating the angle relative to an object's centre. I will keep it in mind, however I'm not sure if it'll always apply to the geometry I want to create. I'll quickly lay out my general intentions:

Firstly, majority of my geometry will be created from tiles, which I think would make dynamic calculations a bit difficult.
Secondly, I wish to create a lot of unique slopes/curves that my player could maneuver alone, like the examples below.

Angled Movement Doc Type 2.png The first image is my main goal thus far.

I'm basically trying to achieve a Sonic the Hedgehog movement system, which involves walking along/up/down slopes while adjusting the angle to match the curve. Do you think your idea would fit with these factors?
EDIT: Maybe if I calculated relative to a tile?
 

NightFrost

Member
Okay so we're talking of a large level made of curving lines instead of walking on a single small object. I think that if the tiles can consistently be given an outside and inside, the logic could still be used. Thinking on it, the way I might start approaching this would be a data structure that describes a series of lines and curves connected to each other, to be used as ground level. While graphically it would appear the player is running across tiles, it would actually be aligned to this line data. I haven't actually touched GMS2 tile stuff, but I know you can find out tiles by position. The tile ID would then be used to refer some line or curvature data and used to align the player, tile by tile as they move. So a system based on reading tiles should also be feasible.
 

Fulbo

Member
A data structure? Admittedly, I haven't tried using them before in GameMaker, but they're likely a good place to start.
Having just read up on them a bit, I notice that there's a grid type that could be pretty handy in this instance. Like, let's say a ds_grid had the same size as a regular tile. Perhaps if I were to check over every pixel in a tile and see if they're blank or not, I can assign a value to the ds_grid saying whether they or not? Like '0' for blank, '1' for coloured? And use those values to determine if I need to do angle calculation?
Hmm... Honestly, I'm not sure if what I described fits into defining 'a series of lines and curves connected to each other'. I don't think I've tried anything like that before, per se. That may be because I'm overthinking it.
If it's not, might I trouble you for a general example of how I could perform this?
 

Fulbo

Member
Ran into this article a few years back - should give you clues as to how you might tackle your own.

http://info.sonicretro.org/SPG:Solid_Tiles
Thanks Relic. I actually already knew about the article, and I've been referring to it for my game. I've just been having trouble making it work in GameMaker.
Regarding tiles, so far I've collected the horizontal and vertical heights of each tile (height representing the highest pixel in each cell, or row). I didn't know how to do the angle values it was talking about, though I now may have an idea.

What if I were to do something like point_direction, and have a function that determines the angle each tile would be at? Something like this:

Potential Angle Calculation.png Just start in the first column to have a pixel, and stretch out the line onto one of the preceeding columns (with the biggest height). Now that I know about ds_grids, I could create complimentary grids for each tile, and store the angle values in each adjacent cell. Then I could call them in during angle calculations.

Could that potentially work?
 

Fulbo

Member
Cheers on sending me this 3dgeminis.
What I've gathered from a lot of GameMaker resources on physics is that they're best suited for objects and collision circles. That makes sense. Shame there's not a lot of code demonstrations for tileset/map manipulation.
Anyways, I've decided to just go the object + place_meeting + etc. route for now. Seeing how physics platforming is a first undertaking for me, I probably shouldn't try a system far beyond my skill.
Thank ya kindly for offering your help, everyone!
 
Top