### Author Topic: Spherical camera collision  (Read 2332 times)

#### Thomas.

• double
• Posts: 833
##### Spherical camera collision
« on: September 21, 2012, 06:49:40 pm »
Egon, could you check if the CollisionEvent.getFirstContact() is right when you use World.checkCameraCollisionSpherical(SimpleVector, 10, 1, true)? I think returned SimpleVector is bad in my game.

#### EgonOlsen

• Posts: 11899
##### Re: Spherical camera collision
« Reply #1 on: September 22, 2012, 05:27:08 pm »
The docs say:

Quote
If the algorithm is spherical collision detection, this isn't the first point but the end position (caused by the way this algorithm works).

Maybe that causes the confusion?

#### Thomas.

• double
• Posts: 833
##### Re: Spherical camera collision
« Reply #2 on: September 22, 2012, 06:12:28 pm »
I know about this. If collided plane is under camera, y of returned SimpleVector is every same as camera position. Is it right?

#### EgonOlsen

• Posts: 11899
##### Re: Spherical camera collision
« Reply #3 on: September 22, 2012, 09:20:10 pm »
It might be...looking at the code, i don't see anything wrong. If the the camera is about to move inside the plane and it's distance from the plane is the radius of the sphere, then it will be adjusted to hover above the plane in the distance of the radius. And the fist contact vector shows this. What are you using it for anyway? For FPS movement, ellipsoid is way better.

#### Thomas.

• double
• Posts: 833
##### Re: Spherical camera collision
« Reply #4 on: September 22, 2012, 09:51:49 pm »
I have camera with radius 10. I expect if camera collide with plane that is under, returned y of vector will be camera position + <0; 10>. Y of returned vector is same as camera position, but direction length is <1 and speed is 1, so it does not make sense for me... Spherical collision is for underwater moving. And FPS movement... from my testing ellipsoid is good when all objects in the scene are least as height as ellipsoid's half height, otherwise it causes a lot of unexpected things. Could you implement capsule collision detection, please? when you take a minute off... I offer bribe in the form of some model for your game
« Last Edit: September 22, 2012, 10:05:07 pm by Thomas. »

#### EgonOlsen

• Posts: 11899
##### Re: Spherical camera collision
« Reply #5 on: September 22, 2012, 10:42:09 pm »
I'm not sure if i understand exactly what you mean...a drawing might help.

Regarding collision detection: Sorry, but i'm not going to add any other means of collision detection and i'm not sure what the problem with ellipsoid collision detection should be!? It's the only approach that lets you climb stairs or obstacles reliable. It might be needed to tweak the parameters to match your scene though. It might also be unwanted that it collides with the actual geometry of the collision target but in that case, you can use collision meshes instead (there's no build-in support for this, you have to code it yourself), i.e. a simplified mesh that is used for collision detection only. In my RPG thing, i'm using this for fences and NPCs to prevent the player from climbing up on NPCs... I simply have an option in my views to enable collision meshs. In that case, i calculate a bounding box of the mesh and add it as a child. Before a collision detection, i set the object to invisible and the collision mesh to visible, do the collision detection and reverse the setting.

#### Thomas.

• double
• Posts: 833
##### Re: Spherical camera collision
« Reply #6 on: September 22, 2012, 11:19:53 pm »
Length of direction is smaller than 1. Camera radius is 10. Speed is exactly 1. Slide is on (true). What does not make sense to me -> returned contact is as high as camera position.

I'm using different mesh for rendering, movement, shot and interaction for maximal speed. But if you use ellipsoid collision detection for movement and any of objects will be smaller than position of ellipsoid, camera sometimes jumps on the object, sometimes comes into the object. I tried a lot of combinations for tweak ellipsoid collision, but nothing was correct. You can try it. And BB as collision mesh, is not the best way for indoor scenes.
« Last Edit: September 22, 2012, 11:24:59 pm by Thomas. »

#### EgonOlsen

• Posts: 11899
##### Re: Spherical camera collision
« Reply #7 on: September 22, 2012, 11:34:23 pm »
Length of direction is smaller than 1. Camera radius is 10. Speed is exactly 1. Slide is on (true). What does not make sense to me -> returned contact is as high as camera position.
That's what the docs say: ...but the end position. The end position is the position of the sphere's center after resolving the collision...which is 10 units away from the plane.

I'm using different mesh for rendering, movement, shot and interaction for maximal speed. But if you use ellipsoid collision detection for movement and any of objects will be smaller than position of ellipsoid, camera sometimes jumps on the object, sometimes comes into the object. I tried a lot of combinations for tweak ellipsoid collision, but nothing was correct. You can try it. And BB as collision mesh, is not the best way for indoor scenes.
Well, use whatever suits your needs best. I just don't understand the problem here. I used ellipsoid collision detection on outdoor, indoor and whatever scenes and it worked fine all the time. The only drawback is that sometimes you start to climb objects that you don't want to and i usually solve this by using collision meshs as described in my previous post.

#### Thomas.

• double
• Posts: 833
##### Re: Spherical camera collision
« Reply #8 on: September 22, 2012, 11:39:26 pm »
OK, tomorrow I'll do some example of my problem. And about spherical, now it is clear, I just understood end point differently
« Last Edit: September 22, 2012, 11:41:00 pm by Thomas. »

#### Thomas.

• double
• Posts: 833
##### Re: Spherical camera collision
« Reply #9 on: September 27, 2012, 05:58:13 pm »
I finally found some time and created a test application for the ellipsoid collision.

http://dl.dropbox.com/u/26148874/Collision%20test.zip

#### EgonOlsen

• Posts: 11899
##### Re: Spherical camera collision
« Reply #10 on: September 27, 2012, 09:57:11 pm »
Of course it gets stuck that way...your code ignores the y-vector of the corrected direction vector by setting it to 0. That way, the ellipsoid can never climb the obstacles and runs into them. And once it does that, ellipsoid collision detection can't resolve the situation (even more because y will still be set to 0). Just remove the temp.y=0; line and will work better.

#### Thomas.

• double
• Posts: 833
##### Re: Spherical camera collision
« Reply #11 on: September 27, 2012, 10:15:54 pm »
Thanks, it helped, but still is not right. Ellipsoid is not moving smooth.
« Last Edit: September 27, 2012, 10:17:38 pm by Thomas. »

#### EgonOlsen

• Posts: 11899
##### Re: Spherical camera collision
« Reply #12 on: September 27, 2012, 10:58:44 pm »
No idea what you mean...i never ever use anything else and it works just fine!?

#### Thomas.

• double
• Posts: 833
##### Re: Spherical camera collision
« Reply #13 on: September 27, 2012, 11:05:07 pm »
You can try remove temp.y=0 line and see what happens. You can set Config.collideEllipsoidThreshold by touch turn up/down...