cassius Posted July 28, 2015 Share Posted July 28, 2015 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. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
thehankinator Posted July 28, 2015 Share Posted July 28, 2015 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. Quote Link to comment Share on other sites More sharing options...
cassius Posted July 28, 2015 Author Share Posted July 28, 2015 I think its something to do with the player being airborne and its y co ord value at the time of being airborne Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
BluHornet Posted July 30, 2015 Share Posted July 30, 2015 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. Quote Link to comment Share on other sites More sharing options...
cassius Posted July 30, 2015 Author Share Posted July 30, 2015 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. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Athos Posted July 30, 2015 Share Posted July 30, 2015 (edited) Ah, my mistake. I misinterpreted the code you posted. Well, I think the best way, as already suggested by thehankinator and BlueHornet, is to compare the player's Y velocity on collision. Edited July 31, 2015 by Athos Quote Link to comment Share on other sites More sharing options...
cassius Posted July 30, 2015 Author Share Posted July 30, 2015 What I was trying to say is if player is airborne and at a height over 5.0 meters. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
beo6 Posted July 31, 2015 Share Posted July 31, 2015 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. Quote Link to comment Share on other sites More sharing options...
cassius Posted July 31, 2015 Author Share Posted July 31, 2015 The velocity thing might work. But maybe the simple answer would be just put a railing up as you probably would in real life. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
BluHornet Posted July 31, 2015 Share Posted July 31, 2015 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!") Quote Link to comment Share on other sites More sharing options...
beo6 Posted July 31, 2015 Share Posted July 31, 2015 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. Quote Link to comment Share on other sites More sharing options...
cassius Posted July 31, 2015 Author Share Posted July 31, 2015 Some really goo answers here. Thanks to all. I try velocity code later tonight. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Recommended Posts
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.