C++ - Check if camera is touching the terrain (Collision)

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

C++ - Check if camera is touching the terrain (Collision)

Post by LunaRebirth »

So I've been looking up numerous differently worded sentences to find the answer to this topic, and I just can't seem to find anything.

Long story short, I want to find if the camera is on the terrain. I'm using the collision tutorial code.

Trying to make a jump where the camera goes up a distance before falling down, but you can only jump if something is directly underneath of you.

To answer any questions, I did do a setPosition for the camera, but I'm doing this for an uneven terrain, so if you were on top of a hill, you could jump then wait until you stop going up to jump again (like you're flying).

Any help is appreciated.:) Thanks in advance.

-Luna
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: C++ - Check if camera is touching the terrain (Collision

Post by thanhle »

I don't use the terrain scenenode yet. But I think you can get the height by feed it X, Z position.

For camera affect under gravity using simple motion law ignoring air friction.

V^2 = U^2 + 2a(Ds)
V = u + at
S = So + ut + 1/2at^2

Just apply the formula to find Y direction at anytime when jump, then compare with the terrain Y position to prevent go through. Assume jump velocity u is known.

Regards
Thanh
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Re: C++ - Check if camera is touching the terrain (Collision

Post by LunaRebirth »

I don't understand your method.
I can find your current position at jump, then increase the Y to a certain Y above where you jumped. However, if you happen to be jumping and reach that max, I have no way of detecting if you've hit the ground or not. So you can jump again.

If I make the jump delay so they can't jump after so long, of you jump off a mountain you'll be able to jump in air again.

I need some way to find true or false if you are on the ground or not.
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

Re: C++ - Check if camera is touching the terrain (Collision

Post by Seven »

If using a terrain scene ode there is a getheight(x,a) function you can check against your character pos.y
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Re: C++ - Check if camera is touching the terrain (Collision

Post by LunaRebirth »

Thank you, I'll look into it. Does this method go for the overall height? Or the height of the vertex below your camera??
Post Reply