[Resolved] Problem when object hits 2 objects

Hello,

I am working on a game, and the game has to detect wether the player is grounded or not.
Now I did this trough a boolean variable which is turns true whenever the player collides with an object, and turns false when the collision goes into “ended” state. It all works fine except when sometimes I hit 2 objects at the same time.

What I think happens:

  • Player is on object1, grounded = true
  • Player is still on object1, but hits object2 while connected to object2. grounded stays true
  • while at all times still connected with object1, player disconnects with object2, grounded = false

But the player is still on object 1 so should be true

Is there anyway to check if the player is colliding with any object and to only turn the grounded false when the object is absolutely NOT colliding with anything else.

Cause now it turn false when colliding stops with one object but it does not check wether its still collided to another object before turning false. And I cant find a way to fix that :frowning: [import]uid: 118839 topic_id: 25793 reply_id: 325793[/import]

Give the ground a name, eg;

ground.myName = “ground”

In the collision function check if event.other.myName == “ground” then set whether or not the player is grounded accordingly.

Does that make sense? :slight_smile: [import]uid: 52491 topic_id: 25793 reply_id: 104393[/import]

Thanks for the reply,

But I already did that (maybe i should have mentioned it)
But the problem is I cannot call all my objects “ground” that have to act as a ground.

For example there is a trampoline in my level, the player will bounce off when falling on it, but if the player rolls over/against it without bouncing off it still has to act as a ground. Cause the player bounces off only when having enough speed.

But for making it bounce off I had to give it a different name then the ground.

So that still gives me the same problem. When it hits both my trampoline and the ground itself, and then disconnects from one off them without disconnecting from the other, it will still set grounded to false.

I hope you understand my problem.

EDIT: I just came up with an idea, but I dont know if it works yet. So im going to try that now.

What if i make a different boolean for the trampoline, and make the player be able to move either if the ground or trampoline is touched. In theory it sounds good to me so im going to try that now! Ill let you know if it worked! [import]uid: 118839 topic_id: 25793 reply_id: 104604[/import]

It worked!

I dont know if it is the most efficient solution, but giving every object (that has a chance to collide with the player at the same time as another obect) its own name and its own boolean variable. And then check with or operators if the player is on one off them, I was able to solve the problem.

I found out even when 2 object are both called ground, and collide at the same problem with the player, the problem still occurs. But when everything has another name and variable assigned there is no problem.

Still I would appreciate it if somebody knows a more efficient way that costs less coding :slight_smile: [import]uid: 118839 topic_id: 25793 reply_id: 104616[/import]

Everything should have its own name (in this case), yes.

If you show your code someone may be able to advise on cutting it down, although if this works well it sounds like a solid solution :slight_smile: [import]uid: 52491 topic_id: 25793 reply_id: 104808[/import]