Author Topic: Collision help  (Read 4068 times)

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Collision help
« on: March 18, 2017, 02:34:16 pm »
Hi I been trying to figure out this by myself but cant manage to figure it out. To pick up objects in my game I have implemented the collisionlistener, it worked out fine. But now when I want to make my planets solid I have tried to check when im colliding with them. But the listiner is only responding when the camera hits the object.

Code: [Select]
Object3d spaceship = a loaded 3ds modell
Object3d earth = a loaded 3ds modell

spaceship.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
earth.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

 earth.addCollisionListener(this);

Here is a video so you can see what I mean.

https://youtu.be/dmrYE05Q3MA


Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Collision help
« Reply #1 on: March 19, 2017, 09:54:57 pm »
well well well after reading up some I checked the code I used your code from the car example to follow my spaceship wish included

Code: [Select]
world.checkCameraCollisionEllipsoid(delta.normalize(), new SimpleVector(20, 20, 20), len, 3);
After I realised this I knew had to change the code or check if anything touched the spaceship. Since im lazy I solved it using checkself and went on from there. Still trying to figure out the best way of making an object solid. If you guys have any tips please give me some.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision help
« Reply #2 on: March 20, 2017, 08:33:22 am »
I'm not sure what you mean!? Is it solved now or not?

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Collision help
« Reply #3 on: March 20, 2017, 09:49:02 am »
I thought I solved it but I didnt. Like I think I dont really understad the basic of the collision because sometime I can make it work and sometimes not. So basically I want to make a sphere solid. The way im using is adding a adding a listiner to earth and then putting

world.checkforcollision(spaceship.transformedcenter, earth.translation, 5)

You should sell leasons or make a course because I would pay you by the hoar for some explaining.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision help
« Reply #4 on: March 20, 2017, 12:01:57 pm »
Have you seen the wiki entry? Maybe it helps: http://www.jpct.net/wiki/index.php?title=Collision_detection!?

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Collision help
« Reply #5 on: March 20, 2017, 01:42:41 pm »
ye I read it and I tried to read all of the exampels. But I have a hard time understanding how to detect the whole sphere and not only the center and even how I shall manage to make it solid after I detect the whole sphere.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision help
« Reply #6 on: March 20, 2017, 02:25:23 pm »
Collisions in jPCT are always bounding "object" (ray, sphere, ellipsoid) agains actual geometry. In your case, the planet is the actual geometry. There's no need to make it "solid" or anything. It already is. The sphere/ellipsoid that you define in the method call is the bouding object for the colliding entity (a moving ship, the camera etc.(, not the collision's target (your planet).
Then you call the collision methods (in your case, most likely ship.checkCollisionEllipsoid(...)) and you should be fine. You might have to adjust the collideOffset setting in Config, because it usually isn't suitable for large scales as it is by default.

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Collision help
« Reply #7 on: March 20, 2017, 03:00:41 pm »
I will try hard after school.

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Collision help
« Reply #8 on: March 20, 2017, 03:11:11 pm »
I just have to confirm what I shall write in the spaceship.checkforeppliode() to check the whole sphere. shall i search for the translation? or how can I check the whole sphere?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision help
« Reply #9 on: March 20, 2017, 03:35:23 pm »
You don't. That's what I tried to explain. The collision happens betwenn an sphere/ellipsoid as an approximation of your ship with the actual geometry of your planet. There's no need to find a matching sphere for the planet, it's defined by its very own geometry already.

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Collision help
« Reply #10 on: March 20, 2017, 11:16:39 pm »
ok im starting to understand how I shall use it. The main problem was the sphere I loaded, I dont know because of it's size or what it is. I played around with some primitives and it worked fine. Tomorrow I will play around with the offset or just make a new sphere. Thanks for the help, still i recomend you to start a course on udemy och sell som favors @ fiverr. You can earn som gold.

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Collision help
« Reply #11 on: March 21, 2017, 11:47:33 am »
Hi again it was no problems with the sphere I just needed to read your comments a few times and some trial and error. Now the collision works fine.