Distance from ground?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
LosNir
Posts: 43
Joined: Wed Dec 19, 2007 6:38 pm
Location: Israel
Contact:

Distance from ground?

Post by LosNir »

Hello,

I'm currently making my Jump action after i realized that the Jump action for the FPS Cam is awful.

I did "everything" but i got stuck on a very important check that is the main reason why i decided to make my own Jump: the ground distance check.

If i won't check that, i would be able to to jump and jump and jump in the air... and i don't want that.

I tried to use this

Code: Select all

      bool collision(ICameraSceneNode* one, ISceneNode* two, int size) {
           if(one->getAbsolutePosition().getDistanceFrom(two->getAbsolutePosition()) < size)
           return true;
           
           return false;
      } 
it works, but it gives me the distance in the Z axis, and i need the Y.
But then i realized that it won't even help me, because it will calculate the distance from the center Y of the map (y axis: 0):

Image

So basically it will calculate the distance from 0 to 50, so the distance would be 50.

But if i was on a lower floor?
lets say on y axis -50, the distance would be -50, and these are different things.

Say after i explained the problem, i need to get a distance of 0 from ground to camera, so it means i need to get the distance from the nearest ground below the camera and the camera.

like this:

Image

So how i can i do that?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

What's your "ground"? A height field? A mesh? A flat plane?

How accurate do you need the collision check to be? A point against the ground, or an area against the ground?

Have you tried using standard collision response animator (as per example 07.Collision)?

You could use a collision response animator with a 0 gravity and handle the jump/gravity yourself. Check the position and after device->run(); if it's higher after calling device->run(), then that indicates that the node is on the "ground".
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Maybe instead of checking against the "ground" check against the current camera position so when you jump 5 units (Y axis) it will be 5 units up from the current camera position which will work on whatever "ground" distance you have..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
mqrk
Posts: 16
Joined: Mon Dec 10, 2007 5:55 am

Here's an idea

Post by mqrk »

I'm not familiar enough with the Irrlicht API to write the actual code, but hopefully you can get the idea from this pseudocode:

Code: Select all

//Create a line going straight down from the camera
line.start = line.end = camera->getPosition();
line.end.y -= MAX_CONCEIVABLE_DISTANCE_FROM_GROUND;

//See where it collides with the level mesh and store it in collisionPoint
checkCollision (triangleSelector, line, collisionPoint);

//Get the distance between the camera and the collision point
groundDistance = line.start.y - collisionPoint.y;
You can look at the collision tutorial for the actual syntax.
Also, don't forget to take into account that when you are "on" the ground, the distance from the camera to the ground is not zero.

Like I said, I am new to Irrlicht so take my advice at your own risk... no guarantees.
LosNir
Posts: 43
Joined: Wed Dec 19, 2007 6:38 pm
Location: Israel
Contact:

Post by LosNir »

rogerborg

It's a q3 mesh.
i looked at tut7 but there is no mention for this,
I need it to be a point, i got collision and gravity but this is not the problem.

The problem i that there are floors and stairs in the mesh, and let say y axis 52 and y axis -2 could be both ground.

MasterGod

As i said to rogerborg, it will work but only at the same y axis, for example if the player will jump on stairs, the jump action won't function anymore, because the y axis are different.


mqrk

Nice idea, thank you, but what is "MAX_CONCEIVABLE_DISTANCE_FROM_GROUND"?

Edit:

ok, i think i solved it with ISceneNodeAnimatorCollisionResponse->isFalling.
It works great, but one problem though it has a some kine of delay,
it says i'm falling even i'm in the ground, and then says i'm not after about 3 seconds.

I started to draw the XYZ axis in the screen, and it looks like when i jump and fall on the ground the y axis decrease even i'm in the ground!

What is the problem here?
mqrk
Posts: 16
Joined: Mon Dec 10, 2007 5:55 am

Post by mqrk »

LosNir wrote: what is "MAX_CONCEIVABLE_DISTANCE_FROM_GROUND"?
That would be the length of the line you are using to check where the ground is. If the line is 10 units long, then you won't "find" the ground if you are further than 10 units away. Basically, you just want to replace that with a really high value like 1000.
Post Reply