Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Moving along Slopes?  (Read 1499 times)

0 Members and 1 Guest are viewing this topic.

King Tetiro

Leader of Phoenix Heart
Moving along Slopes?
« on: September 05, 2012, 04:20:18 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3549
Hey folks, it's been a while. Alot of stuff has happened. Got a 2:1 at university. Now look for work, been working on indie games etc.

But today I'm stuck. We all remember the irritating moving along slopes problem right? Well finally work on a project where I actually need this in the game, I have spend the last 3 hours trying to fix the problem but with no luck. I've had a look at the various movement engines here at ZFGC including the MC engine to try and understand how it and I'm left confused due to the complexity the engines themselves. Along with the heat, I have been left frustrated. So I've given up trying to solve it myself so I thought I'd ask here again.

Right now the engine is pretty standard. As I've scrapped all my attempts and started the movement engine from scratch again (7th start again)

Code: [Select]
if place_free(x + m,y + n) //(m and n are calculated based on the angle and the distance intend to travel)
{
x = x + m;
y = y + n;
}

I'd really appreciate any help. Especially if someone is able to help me solve the problem by explaining how to solve it.
Logged
  • Phoenix Heart
Re: Moving along Slopes?
« Reply #1 on: September 05, 2012, 05:46:01 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6588
I am busy with other stuff (I might be able to help out more later but I don't know) but here are two things that I find useful when doing collisions:

1. Breaking up x/y movement so that you move x first then y second or vice-versa.
  This simplifies collision behavior. For example, if you move down into a slope you will either go left/right if that is free or will have to move backwards up (and if you are moving left/right already, just move backwards up - if you move into the slope you should stop, if you move away from the slope you don't have to worry about it)
2. Checking for two collisions on each side of the object, storing what those were into variables.
  If moving down and you run into a slope on the left side and nothing on the right side, you're going to try to move to the right right. The further collision code then just has to check if it can be outside of what the left side collided with if it tries to move right. If not then it might try to move back and to the right, and if that doesn't work it just moves back.
Logged

King Tetiro

Leader of Phoenix Heart
Re: Moving along Slopes?
« Reply #2 on: September 05, 2012, 06:02:19 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3549
I am busy with other stuff (I might be able to help out more later but I don't know) but here are two things that I find useful when doing collisions:

2. Checking for two collisions on each side of the object, storing what those were into variables.
  If moving down and you run into a slope on the left side and nothing on the right side, you're going to try to move to the right right. The further collision code then just has to check if it can be outside of what the left side collided with if it tries to move right. If not then it might try to move back and to the right, and if that doesn't work it just moves back.

Breaking up the movement is a no worry at all.

So let me check to ensure I have it right for number 2. If the collision test fails for an exact directional movement, I should check to see if I can slope from either side before attempting to move the player along the slope?

Also, I didn't understand sentence in bold. Could you simplify that in any way?
Logged
  • Phoenix Heart
Re: Moving along Slopes?
« Reply #3 on: September 05, 2012, 07:19:42 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6588
1. The dark gray square is the character, the light gray triangle is the slope - the character is moving down.
2. Think of the character as being in two halves. The blue is the left side, the purple is the right side.
 
A. In this scenario, the character hits something when going down, it can't uncollide itself from the slope by
   just moving to the left, so it has to back up. It knows to try to move left because its blue left side did
   not originally collide with anything. However, when moving left, it still has to check if something else is
   to the left.

B. In this scenario, the character hits the slope on just its right side. If the character moves to the left
   it can uncollide with the slope - it doesn't have to go back. If it did go back and to the left this would
   look like it was "stair stepping".

It can only move to the left though if no other obstacle is there.

A diagram is attached.
Logged

King Tetiro

Leader of Phoenix Heart
Re: Moving along Slopes?
« Reply #4 on: September 05, 2012, 07:50:54 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3549
1. The dark gray square is the character, the light gray triangle is the slope - the character is moving down.
2. Think of the character as being in two halves. The blue is the left side, the purple is the right side.
 
A. In this scenario, the character hits something when going down, it can't uncollide itself from the slope by
   just moving to the left, so it has to back up. It knows to try to move left because its blue left side did
   not originally collide with anything. However, when moving left, it still has to check if something else is
   to the left.

B. In this scenario, the character hits the slope on just its right side. If the character moves to the left
   it can uncollide with the slope - it doesn't have to go back. If it did go back and to the left this would
   look like it was "stair stepping".

It can only move to the left though if no other obstacle is there.

A diagram is attached.

Ah I see, so A scenario wouldn't trigger a sloping but B scenario would? Or have I missed something?
Logged
  • Phoenix Heart
Re: Moving along Slopes?
« Reply #5 on: September 05, 2012, 08:49:23 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6588
Scenario A and B were really just to illustrate how sometimes you can just move to the left to uncollide with the slope, whereas other times just moving to the left will not uncollide you with the slope (in this case you would have to move to your previous y position prior to movement). The goal of slope collisions is really to "correct" the characters motion so that it acts as if you are trying to move diagonally (e.g. pressing down and going left/right).

I'll try to make a simplified Game Maker example later today/tomorrow which shows these concepts in a more interactive form.
Logged
Re: Moving along Slopes?
« Reply #6 on: September 06, 2012, 01:51:01 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6588


I put together some sample code to explain what I was talking about. I tried to keep it simple, but if there is anything odd about it that isn't quite clear let me know and I can explain it further.
Logged
Re: Moving along Slopes?
« Reply #7 on: September 06, 2012, 01:12:39 pm »
  • AKA "Micah DS"
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1341
I also accomplished this in my Spirit's Quest project. I'm pretty sure Diminish's is better (I haven't looked at it), but I do also have moving platforms and slopes and more advanced stuff like slopes that you can jump up through and land on, jump down from, etc. I released all of the data in my Spirit's Quest topic, but I've attached the editable of just the collision engine so you don't have to download the entire project. My code wasn't the most efficient, but everything works without flaw, and you should be able to look at it and see the general idea.

To give you an idea of what I did: I pretty much just had it loop according to the character's x and y speed and checked for collisions on each step of the loop. If the character collided with an object it would exit the loop. The slope code is in the loop of course, and it's a bit more complex than that with the solid and passable slope types, etc. If you look at it, you should understand what my idea was. There is also a slippery type in there, in case you might want to check that out.

Note: There are a lot of unnecessary calculations that come up because of the character design having a big head and small body collision. So you can pretty much ignore the "mask" changes and all of the "position correction" code. That code is separate from the x/y movement though (mostly).


I hope this is useful!
« Last Edit: September 06, 2012, 01:15:56 pm by Frozenç‚Ž »
Logged
  • My Music
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.046 seconds with 38 queries.