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: [Request / Listing] Collisions with Slanted Barriors Help (Solved)  (Read 1919 times)

0 Members and 1 Guest are viewing this topic.
[Request / Listing] Collisions with Slanted Barr...
« on: June 23, 2006, 01:24:19 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I have tried making a collision to where if your character hits a diagonal block that the character will continue moving   I failed of course, so that is why I am asking for help.  The basic concept of what I am asking is as provided by this situation:

An object is moving left towards a wall with a positive slope ( / ).  When the object collides with the wall, its direction is now based on the slope itself (not necessarily by the slope of the sprite, but a basic 45 degree slope).  The object will thus move down and left.  If the object goes up towards the same wall, the object will then move up and to the right as a result of the slope.

So, can anyone help me?

EDIT: Also, it would be nice if the help could work with x and y movement in a prioritized fashion like Goodnight's walking engine, just to be clearer.
« Last Edit: March 18, 2012, 06:48:27 am by Niek »
Logged

aab

^ Evolved from a Hobbit
Re: Request: Collisions with Slanted Barriors He...
« Reply #1 on: June 23, 2006, 02:15:30 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 992
[edit]
Get a pen and some paper, and draw everything i say  :D
[/edit]

Lets say that a slope has an interval along the x axis [a,b], such that a < b.

Because the slop is only 45 degrees, this simplifies things.

The slope begins at a position (a, some y value) and ends at a position (b, some y value)

Lets call the y value for the beginning position u.

The end points y value will then of course be u, plus the distance from a to b, ie u + (b - a) = u + b - a

Lets call this y value, v.

So, the slop has interval [a,b] along the x axis, [u,v] along the y axis, and goes straight from the point (a,u) to the point (b,v), where a<b and u<v (and of course v - u = b - a )


The y value on that slope for any given x value is defined as being as distant from u as the x value is from a.
This can be thought of as making (a,u) the origin of a new coordinate system.
On that new coordinate system, lets call it XY, and not xy (the screens normal coord system), Y is equal to X on the line/slanted barrier.

If you have an X value, and want to obtain the Y value on that line, you know the it is the same as the X value.

However, we are dealing with xy, and not XY coordinate system.

To make things easy/abstract, we convert from xy to XY, (ie change the x value into an X value) and obtain the Y value through X=Y, then convert it back into a y value.


To convert from XY to xy? Well XY is defined as having an origin such that X=Y=0, at the position (a,u) on xy.
So that means that at x = a, X  = 0, and at y = u, Y = 0.
So, at x = 0, X = -a, and at y = 0, Y = -u
X is a translation of a from x, and Y is a translation of u from y

ie:
To convert from an x value to an X value, subtract a, and conversely add a to an X value to obtain an x value.
To convert from a y value to a Y value, subtract u, and conversely add u to a Y value to obtain a y value.
(It helps to draw two axes, one at 0,0 and one at a,u, and convert a point or two on paper)

Are you scribbling lines all over some sheet of paper?

So, to evaluate the y value from an x value within the interval of the slanted barrier (which can be checked easily as standard: player.x >= a and player.x <= b ), you :

subtract a from the x value to get the X translation of it
Get the Y value, witch is the X value..so...do nothing really!
add u to this Y value to get the y translation of it.
And now you have the y value at the ground level of that sloped surface for any x point along it (and of course obtaining the x value from the y value is very easy).

So, you can allow the player to move, calculate the slopes y value, and say "' if player.y is less than slope.y, then player.y := slope.y '" , and the player will be able to move horizontally and never be beneath the slope, as long as the y value when approaching the slope in the interval [a-xspeed, a] is always greater than u, and the equivelant on the other side with b,v. + xspeed etc.
You could then reduce xspeed or multiply it by a factor less than 1.0, when in the closed region [a,b] of the slope if neither jumping nor falling; This should be done so that the diagonal movement is not too fast.

If you wanted levels where some slopes are beneath others however, youll have to make a vertical closed interval which player must be in, in order for that slope to be taken care of. ie define a y1,y2 (tired of a,b ..c,d would just confuse things, its time for some proper notation) such that the slope is only considered at all "' if player.y >= y1 and player.y <= y1 '" This boundary must be wider on the top and bottom, from u and v, by at least more than the players expected maximum vertical movement. Doing this will allow some slopes to lie beneath others, however, an aidditional upsid down slope object will be needed to stop jumping up from beneath the slope (although that can be used often in sidescrollers)


This, however, is for a slop going downwards as x increases, not upwards.
It wouldnt be any difficulty to convert the ideas, and is better anyway as understanding will be needed to implement this, and if you have to work out some of your own things on paper first, it'll help.



...I know <0 about goodnights walking engine however ..





« Last Edit: June 23, 2006, 02:22:37 am by aab »
Logged




I ♥ Sol
.... I ♥ Sol ? wtf how long has that been there? >_> *rrrrrrrrar*
  • MySpace
Re: Request: Collisions with Slanted Barriors He...
« Reply #2 on: June 23, 2006, 02:56:13 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Could the process in any way be simplified by deactivating certain keys?
Code: [Select]
u=keyboard_check(vk_up)-keyboard_check(vk_down);
d=keyboard_check(vk_down)-keyboard_check(vk_up);
l=keyboard_check(vk_left)-keyboard_check(vk_right);
r=keyboard_check(vk_right)-keyboard_check(vk_left);

This part of my code has it so when a direction is pressed, its opposite side is negated.  Think of it as a wobbly tabble.  If I push one side down, the other goes up. 

So, if I were heading up towards a slant block, could I make it so the game would think that I would be pushing up and right following the slope?  But the problem I see in that is when you are fooled into moving diagonally, you are no longer in collision, and are thus left only pushing up, which starts the process of colliding and uncolliding.  Is this practical and/or possible?  Because then, my speed would still be fine, and I could define the key deactivation based on the global direction of my object.

But then, if I were headed up and left towards the slope, I would still have to figure out how to stop the object, but that would not be a problem.
Logged
Re: Request: Collisions with Slanted Barriors He...
« Reply #3 on: June 23, 2006, 03:25:47 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
i would think it would be as simple as moving left if your heading down on a 45 degree angle
you check if your hitting the diagonal block below you and if you are keep moving left until you don't hit it at which point you'd begin to head down again and hit it again and then move left etc.
Logged

Ben

Re: Request: Collisions with Slanted Barriors He...
« Reply #4 on: June 23, 2006, 10:06:45 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
Check out the OOT Community project, this does it. And it works quite well, though I swear you sometimes go too fast, but look through links walking code (try to differentiate from the Z targetting and everything else).
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion

mit

Re: Request: Collisions with Slanted Barriors He...
« Reply #5 on: June 23, 2006, 11:04:24 am »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
As with most things in Game Maker, the mathematically correct way isn't always the fastest. You'd probably get away with just using move_contact_solid() or something similar, as the compiled code runs faster.
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: Request: Collisions with Slanted Barriors He...
« Reply #6 on: June 24, 2006, 01:30:56 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I should have checked the Zelda examples pinned topic.  It turns out that the version of Goodnight's Walking Engine that I customized myself has had an update!  Well, thanks for the help everyone, it helped out and was appreciated.
Logged
Pages: [1]   Go Up

 


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



Page created in 0.041 seconds with 48 queries.

anything