0
$\begingroup$

I have many instances in which I need to use a property to control if the player is on the ground or not. How can I create this? The simple approach that comes to mind is to create a plane over all the floors and give it a property, "floor". Whenever the player is colliding with it, "collide" will be set to true. Else, it will be false. This seems messy and confusing, especially with a large, complex map with rough terrain, ramps, etc. I am looking to create this in a more ideal fashion, how can I create this? Thanks.

$\endgroup$
1
$\begingroup$

Collision with an object that has a Property "floor" is in a lot of situations a good solution. You can have any number of such "floor" objects.

Unfortunately, this might not be sufficient in other situations. E.g. such an object might collide with the top of your character rather than the bottom.

There are other options:

  • have a separate object below the character to detect the floor via collision
  • use a ray along -Z to detect a floor

Edit:

As this checks for any object and you can have as much objects with the property "floor" there is no need for a single floor object.

A different thing is to check if the player remains within expected parameters (area). E.g. if you can't be sure he finds a way to jump outside the level. To avoid that you can surround your level with a "consistency cage". You assume the player never touches it, but if he do you can perform some "corrective" actions. For example: game over, level restart or move him back somewhere within the level.

enter image description here

$\endgroup$
  • $\begingroup$ So would I create a plane that goes over all the floors in my scene? $\endgroup$ – blackhole Oct 5 '15 at 23:16
  • $\begingroup$ Typically you ensure there is always an object (regardless if floor or not). Otherwise when the character slips into a gap it will fall outside of your level (into infinity). If you are not sure if there is a possible gap, you can surround the level with a "security" box. When the character collides with that box it is outside of the expected parameters. So you can act accordingly (e.g. reset the level, game over ...). But this should not be part of the regular game flow. $\endgroup$ – Monster Oct 6 '15 at 4:26
  • $\begingroup$ Can I just give all my game-related objects a prop for this? The ones that the player should be able to collide with already has a property "collide," can I just use this or would walls be a problem? Also, if I use a ray, won't it send a ray only out of the center of the character? What if the side of the hitbox collides, but not the center? $\endgroup$ – blackhole Oct 6 '15 at 21:10
  • $\begingroup$ Sure you can. But ... the purpose of such "collision filter" is that you want to distinguish between collisions of different types. Typically you use the "floor" collision to allow jumps, while jumping is disabled otherwise. $\endgroup$ – Monster Oct 7 '15 at 9:12
  • $\begingroup$ Also, if I use a ray, won't it send a ray only out of the center of the character? What if the side of the hitbox collides, but not the center? $\endgroup$ – blackhole Oct 8 '15 at 1:24
1
$\begingroup$

I am not sure if I understood the question correctly, but the collision mesh can be simpler then the actual floor and still have the information needed to make the object interact properly.

Of course this comes at the price of not having the best precision and giving some areas where the interaction may result in it going through or colliding prematurely but the amount of detail is for you to decide.

$\endgroup$
0
$\begingroup$

wouldn't it be better to give the floor itself a property floor? (maybe a boolean). then you can see if the hitObject you get from your player has this property and if it is true. Also, i've noticed you can set the skin of your armature to be a sensor, and use that as your collision mesh.

$\endgroup$
  • $\begingroup$ Well I don't have every floor as its own object. This is why I wrote this question. I was looking to see how I can do this in a more efficient way than making an object wrap the whole scene's floors. $\endgroup$ – blackhole Sep 30 '15 at 22:29
  • $\begingroup$ i think it's really efficient to give each object you want to interact with a game property, it's not much work when you're making those objects. this way you can also let your player enter different states on different types of objects. for example, you can give an object a property floor, to let it walk on it, or you could give it the property water to bring it in a 'swimming' state $\endgroup$ – Glenn van Acker Oct 2 '15 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.