Jump to content

Recommended Posts

Posted

I need to know if my main character is above a certain height above ground so I can kill it when it falls from this height.

Any ideas?? Thanks.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Posted

Have you tried World::Pick() or any other Pick?

 

I know you are asking in C++ but I think the FPSPlayer.lua script on collision will check the velocity of the player, if it's more N value it kills the player. You might be able to add the same sort of check in C++ or do the height check in lua.

Posted

I think its something to do with the player being airborne and its y co ord value at the time of being airborne

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Posted

there are several ways of doing this one

1. you can compare your players y velocity to a constant

pros - fast and cheap, simple code

cons - could kill the player in appropriately (fast elevators)

2. you could do a pick and compare the distance to a constant

pros - accurate

cons - harder to code, more costly calculation

3. you could do a bounding box from the player down and if the box does not return a terrain or scene entity kill the player.

pros - a mid level cost, accurate enough, easy coding with minimal bug potential

cons - is done on update physics and not update world due to being a collision test.

4. you could do a collision timer on the player. if the time since the last collision with a scene entity exceeds the timer the player dies.

pros - cheap, easy code

cons - I can't really think of any. This does not mean there isn't any I just can't think of any right now.

 

in short without any other information I would probably just use number 4 but there are other considerations. I am also sure there are many other ways to do this, these are just a few I could think of in the past few minutes.

Posted

Some good ideas there thanks fellas.The following did not work

 

if(player->GetAirborne() && playerPos.y > 5.0)

player.alive = false;

 

Caused a crash. Don't know why.Or maybe it worked in the wrong place as the game is set to end when player not alive.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Posted

What I was trying to say is

 

if player is airborne and at a height over 5.0 meters.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Posted

With that code the player would die instantly when for example you have a platform at height 5 or a hill. As soon as the player jumps or falls just a small amount he would die. I thing the velocity test is the best but that depends in how exactly your gameplay should look.

 

To get the correct height above ground you would need to make a constant raycast down from your character.

Posted

The velocity thing might work. But maybe the simple answer would be just put a railing up as you probably would in real life.rolleyes.gif

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Posted

to check velocity you would need something like

 

in C++

 

Vec3 playerVelocity = player->GetVelocity();

if(player->GetAirborne() && playerVelocity.y > 5.0)

{

player.alive = false;

}

 

in Lua

 

local playerVelocity = self.entity:GetVelocity()

if playerVelocity.y > 5 then

self.alive = false

end

 

I would probably make the velocity more than 5 but it is a good start for testing. If you feel it needs raised then you can do so. I would also print a system message when you kill the player so you know why you died. This can greatly help troubleshooting later. It can help find the why am I randomly dying question. You don't even have to remove it really. The player should not die tens of thousands of times so it will not bulk the log too bad. Just add a line to the check.

 

in C++

 

System::Print("Player fell to his/her death!")

 

in Lua

 

System:Print("Player fell to his/her death!")

Posted

Maybe it's also good to think about reallife.

You don't die because your body thinks you have fallen high enough, you die because you hit something too fast.

Or else nobody would die if they got hit by a car.

Posted

Some really goo answers here. Thanks to all. I try velocity code later tonight.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...