Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 984 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
[small snippet] telling slopes from stairs with OB #92806
10/03/06 02:30
10/03/06 02:30
Joined: Jul 2005
Posts: 366
eleroux Offline OP
Senior Member
eleroux  Offline OP
Senior Member

Joined: Jul 2005
Posts: 366
This is a very simple contribution.

I've had some problems with stairs and slopes with the new OBB c_trace collision.
The problem is that the stairsteps will return normals that look like a slope.
This didn't happen with the traditional AABB collision because the AABB box is 'straight', and the new OBB is a spheroid. So the normal returned depends on the point in the spheroid that hits the level geometry.

But, while the player is running on a slope, the normal is constant, and while running up a staircase, the returning normals change all the time. See the blue arrows in the fourth image below: they are all different because they are calculated after different points on the OBB 'perimeter' hitting the stairstep edges.



the use of move_min_z and disable_z_glide doesn't help much because it doesn't differentiate stairs from slopes. (it's also based in collision normals).

I found out that, if you start a c_trace from some quants below the player, it returns a different normal value. So in this code, I'm just using a second c_trace to tell stairs from slopes. If the normal.z values are different, we are standing on stairs.


Code:

vec_set(mG_tempvec.x,my.x);
mG_tempvec.z -=200; //trace 200 quants below (floor)

mActor_height = c_trace(my.x,mG_tempvec.x,
ignore_me + activate_sonar +use_box); //normal first trace

slopecheck = off;
if (normal.z < 0.45) //Potential slope. You may raise this value for less tolerance to slopes
{
oldnormalz = normal.z;
//start a second trace 8 quants below the player origin
c_trace(vector(my.x,my.y,my.z-8), mG_tempvec.x,
ignore_me + activate_sonar +use_box);

if (abs(normal.z - oldnormalz) >0.01)
{
slopecheck = off;
}
else
{
slopecheck = on;
}
}

if (mActor_height>2 || slopecheck)
{
//player is on the air OR a slope. Apply gravity
}
else
{
//player is on ground or stairs. Move freely.
}



Emilio

Last edited by eleroux; 10/03/06 02:32.
Re: [small snippet] telling slopes from stairs wit [Re: eleroux] #92807
10/05/06 15:20
10/05/06 15:20
Joined: Sep 2003
Posts: 648
Switzerland
snake67 Offline
User
snake67  Offline
User

Joined: Sep 2003
Posts: 648
Switzerland
Nice solution. I would like to optimize the code:

vec_set(mG_tempvec.x,my.x);
mG_tempvec.z -=200; //trace 200 quants below (floor)

mActor_height = c_trace(my.x,mG_tempvec.x,
ignore_me + activate_sonar +use_box); //normal first trace

slopecheck = off;
if (normal.z < 0.45) //Potential slope. You may raise this value for less tolerance to slopes
{
oldnormalz = normal.z;
//start a second trace 8 quants below the player origin
c_trace(vector(my.x,my.y,my.z-8), mG_tempvec.x, ignore_me + activate_sonar +use_box);

if (abs(normal.z - oldnormalz) <0.01)
{
slopecheck = on;
}
}

if (mActor_height>2 || slopecheck)
{
//player is on the air OR a slope. Apply gravity
}
else
{
//player is on ground or stairs. Move freely.
}

Re: [small snippet] telling slopes from stairs wit [Re: snake67] #92808
10/05/06 21:29
10/05/06 21:29
Joined: Jul 2005
Posts: 366
eleroux Offline OP
Senior Member
eleroux  Offline OP
Senior Member

Joined: Jul 2005
Posts: 366
You are right! how embarrassing

You know.. comment a line, uncomment another... code gets messy...

Re: [small snippet] telling slopes from stairs wit [Re: eleroux] #92809
10/05/06 22:01
10/05/06 22:01
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Quote:

You are right! how embarrassing

You know.. comment a line, uncomment another... code gets messy...




It is still a nice contribution by you!

Re: [small snippet] telling slopes from stairs wit [Re: Pappenheimer] #92810
10/06/06 23:42
10/06/06 23:42
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline
Serious User
Lion_Ts  Offline
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
The one who nothing does is not mistaken only.
Good contrib. Thanks for this.

Re: [small snippet] telling slopes from stairs wit [Re: Pappenheimer] #92811
10/07/06 11:40
10/07/06 11:40
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
Quote:

Quote:

You are right! how embarrassing

You know.. comment a line, uncomment another... code gets messy...




It is still a nice contribution by you!




The same here eleroux, nice code snippet

Cheers

Frazzle


Antec® Case
Intel® X58 Chipset
Intel® i7 975 Quad Core
8 GB RAM DDR3
SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB
NVIDIA® GeForce GTX 295 Memory 1795GB
Re: [small snippet] telling slopes from stairs wit [Re: frazzle] #92812
10/08/06 02:10
10/08/06 02:10
Joined: Jul 2005
Posts: 366
eleroux Offline OP
Senior Member
eleroux  Offline OP
Senior Member

Joined: Jul 2005
Posts: 366
Thanks all for the kind words !


Look, I was exploring my own code to find out why this works... since the OBB collision is a bit dark for me yet.

I found out that, in the first c_trace (use_box), the 'spheroid' collides with the stair steps edges, thus returning a normal that can be anything between 0.1 and 0.9. This is what makes stairs look like slopes.
However, if we make this trace from BELOW the entity origin, the spheroid has already collided with the stairs! The c_trace (use_box) seems to ignore the already-collided surface and goes ahead, so the next surface it hits is the floor (normal.z == 1.00).

So, there is no need to compare old and new normals. Just, if normal.z is below a certain value (a certain floor slope), make a c_trace again from below the creature, and check for a slope again. if it's really a slope, normal.z will be the same value, otherwise it will be 1.00.
Here is the simpler code, without the need of a old_normal_z variable.

...

Code:


vec_set(mG_tempvec.x,my.x);
mG_tempvec.z -=200; //trace 200 quants below (floor)

mActor_height = c_trace(my.x,mG_tempvec.x,
ignore_me + activate_sonar +use_box); //normal first trace

slopecheck = off;
if ( normal.z < 0.707) //potential slope 45 degrees
{
c_trace(vector(my.x,my.y,my.z-8), mG_tempvec.x,ignore_me + use_box);
if (normal.z <0.707)
{

slopecheck = on;
}

}



Last edited by eleroux; 10/08/06 02:37.

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1