PDA

View Full Version : Hit detection doesn't work with "no contact response" setting. Need workaround



Reaper392
06-28-2014, 03:39 PM
I've been trying to get the basics sorted for an FPS camera in order to build on it later. However, there are problems with making the character jump. After a bit of trial and error I came up with similar system to the FPS tutorial (https://docs.google.com/drawings/d/1_D6mXWPlLoXltH6DRn403cvvh3hGcY_opYl0_qNgmBY/edit?pli=1) from elsewhere on this site, which uses area effectors to push a ball around which represents the character. I have also added the following features:

- Movement forces that scale with horisontal speed (to get better acceleration with the same top speed)
- Instant stopping when the character is not supposed to be moving (i.e. if the player is on the ground and isn't trying to move, then the linear damping is set to 100%)
- Ability to jump if the player is on the ground

However, there is a problem with the jumping. The 'is the player on the ground, and therefore allowed to jump' detector is a collision detector, detecting if the ball is hitting any object. So it will also activate if the player is up against a wall, allowing the player to climb up the wall by holding the jump button which is not something I want to happen.

The solution I came up with was to place a second smaller ball slightly below the ball representing the character (by using an object position event every tick). This smaller ball had its collisions set to 'no contact response' so that it wouldn't collide with the ball representing the player object, but it would still send out a signal if it was hit by anything else. A hit detector was then set to detect a collision between this smaller ball and anything but the player ball. Due to its position and size, it would only be colliding with something if the player was on level ground or a reasonably shallow slope. When the hit detector was active it would allow the player to jump, and when it was not active it would not allow the player to jump.

After far too much testing I've found that there is a bug where objects set to no collision response do not send out an impulse when colliding with something as they are supposed to. I have tried the following workarounds, all of which have failed for various reasons:

Same system as above, but changing the physics type when doing collision detection only
- no matter what physics types I use, the player ball will either collide with the detector, or the collision detector will not work. I've assumed that the flowcharts are calculated from top to bottom as they are in trials evo

Object as collision detector below the player ball, not touching it, allowing jumping when active
- Doesn't detect the ground, or very thin surfaces

Object as collision detector surrounding the top half of the ball, disabling jumping when active
- best solution so far, but does not allow the player to jump when they are near a wall no matter what ground they are on

If anyone has any other ideas for a workaround that I can use until the devs fix the broken "no contact response" setting, that would be great

dasraizer
06-28-2014, 04:13 PM
hi, unfortunately the only trigger that works as no contact response is the area trigger which fortunately can be OPE'd to the base of the ball and not even worry if its in contact with it as you can set its collision state to static and ground and any instances or object types you want or exclude and select the ball ( i think is better in this case), so it activates on every surface.

the area trigger seems to sleep after some small time if its inactive, OPE to player should be fine but you may want to add a small oscillation to one axis so it stays alive, i did this by
adding on the X axis a VDS set to 0.01 and controlling it by a SVE set to multiply it by -1

dasraizer
06-28-2014, 04:24 PM
oh forgot physics has to be set on the area trigger, even though its OPE works fine, may be worth turning gravity off though if the OPE is disabled for any period of time.

Reaper392
06-28-2014, 04:27 PM
Thanks, I'll try that later on today

Reaper392
06-28-2014, 10:07 PM
Sorry for the double post, but i just wanted to say thanks again because it worked perfectly. As an added bonus it is relatively straightforward to add ladders or jet packs if i wanted to now :D