Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Multiple collision producing jittery movement?

Author
Message
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 27th Feb 2015 14:49
I was trying a 3D driving snippet that I picked up somewhere, and noticed that if my car_obj was colliding with 2 object(a cube and a ground plane) at the same time, the movement seems to be jittery.

I suppose this is caused by the function ObjectSphereCast and GetObjectRayCastSlideX(0) returning the cube collision on 1 frame, and the ground collision on in the next frame (though I'm not sure).

If I disable collision detection for the ground plane (so that the car_obj only collides with 1 object, the cube), the movement is smooth.

I tried to detect collision twice in a frame, and re-position the car_obj twice, but still doesn't seems to work.

Can this be considered a bug? Any possible workaround?

The codes:
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 27th Feb 2015 18:25
yes the problem is here, but then the ground is not visible^^
if hit>ground_obj and hit <= building_objs

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Mar 2015 19:17
I remember that code

The main problem you'll always encounter with doing collision against multiple objects is that they can interfere with each other. In this game there was only two types of object I was interested in, the collision with the "building" and the collision with the way points. Which is why I used:



So I checked collision with all the objects and then just determined if the object hit was either a building or a way point. The variable "building_objs" being the id of the last building object. The collisions don't interfere with each as the player won't be colliding with more than one building or way point at the same time and won't collide with building and a way point at the same time either.

However, in order to get this to work I had to turn off the collision for the car, the starting cone and the ground (the ground is only there was visual purposes). What you're seeing with the way you modified the code is that the sphere cast is always detecting collision with the ground and this interferes with the collision with the buildings.

This was one of the first games I wrote in AppGameKit, and based off a game I wrote in darkbasic, so I might do it differently now. What I might do now is to save all the object ids to variables and then loop through each object to detect collision.

It really depends on what you were trying to achieve. I noticed that you've turned it into a first person example. Are you trying to make a first person game/demo and what the player to go up and down with the terrain? Or up ramps or stairs or something?

hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 16th Mar 2015 15:04
Thanks a lot for the neat driving game, really helpful when having these kind of examples when starting out with AGK.

For now I'm just trying to achieve sliding collision with multiple objects, with the terrain and other objects the player is interacting with, on terrain of multiple height. So I enable the Y component of the collision.

In another project, I set a simple gravity so that the player object is always moving down, only stopped by the terrain. So the player had constant collision with the ground, and with other objects when they collide. These multiple collision became jittery.

If I calculate the collision for each object currently colliding with the player one by one, one at a time, for example the ground and, lets say, a ball, located about 1m abouve the ground, I'm afraid that the following will happen:

1) The player collides with the ground, re-position player ABOVE the ground. No problem here.
2) But next, when the collision calculates the position of player after it collides with the ball, due to the shape of the collision sphere, the player will be pushed a little bit below the ball, which is a little bit below the ground
3) Now, the final position will be 'not touching the ball', but a little bit below the ground. I want it to be 'not touching the ball', and just above the ground, like normal objects would be in real life.

I think this can be overcame with some workaround, but I would like to see how other people would do it. There might be a more simple way to approach this problem.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 18th Mar 2015 23:12
It helps if you can split the map into different elements in the code and treat the collisions with them accordingly.

So in your ball and ground scenario, I'd do the collision with the ball first and then the collision with the ground second. That way the player will always be above the ground as it overrides the collision result with the sphere, so this is fine as long as the player doesn't end up in the sphere.

Here are a couple of examples:

This ones a bit "mine crafty", it works fairly well but it's possible for the player to force their way up a "step" and there is jittering if the player pushes themselves into a corner.



The second one is similar to the first but with the addition of sphere and columns. Here collision with the sphere is done first. Collision with columns second but only the X and Z components of the collisions are used. The collision with the ground is done but here we only concerned with ray casting downward to place the player on the ground.



In this second example, the spheres and columns are placed far enough apart so the player can collide with more than one at a time.

In my experience perfect collision with multiple objects is incredibly difficult. I've never bothered chasing it too hard and find I get better results with good map design, so make gaps either way enough so the player can easily go through or make them so narrow so the player doesn't bother trying to squeeze through. Make step up obviously lower enough or too tall to get over.

A lot of how you deal with collision is based on what results you want or happy with. The general rule of thumb is do as little as you can get away with. If you don't need to Y component of the collision result then don't use it. The less each bit of the collision is doing the less likely there is to be interference and jittery camera.

In the demos I've used a very simple way of dealing with the ground, all it does is place the player on it. If I wanted the player to slide down slopes or slow them down when going up slopes then I'd have to deal with it differently.

Anyway, I hope this gives you some ideas of how to go about it all.

hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 19th Mar 2015 06:43
I see, that's a great idea separating Y collision from X and Z component.
I guess there's no 'one size fits all' solution.
Maybe perfect collison can be achieved with physics, but I rather not
Thanks guys. You all opened my mind the easy way (by easy I mean not spending countless hours headdesking myself )

Login to post a reply

Server time is: 2024-06-16 21:01:45
Your offset time is: 2024-06-16 21:01:45