www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: athanazio on December 10, 2006, 04:28:28 am

Title: collision basics
Post by: athanazio on December 10, 2006, 04:28:28 am
Now my journey in the JPCT its in the collision phase ...

Well sometimes the Character is able to go thru the cube, sometimes it hits the cube, and got stopped, so sometimes its working, sometimes not ... any help would be great !


look what I'm doing :

I have a class that Wrap around every Object3D that I create, and this is the translate method

Code: [Select]
public void translate(SimpleVector where) {
int collisionObject = w.checkCollision(getTransformedCenter(), where,
5);
if (collisionObject == Object3D.NO_OBJECT) {
super.translate(where);
syncTranslate(where);
}
else {
System.out.println("colide with " + collisionObject );
}
}


the basic idea is dont allow those objets to go thru other object ... :)

and this is the init() method of my Game class
Code: [Select]

public void init() throws Exception {
System.out.println("Config.maxPolysVisible=" + Config.maxPolysVisible);
Config.maxPolysVisible = 12000;
Config.collideOffset = 250;
Config.tuneForOutdoor();

addTexture("alita2", "models/alita/alita2.jpg");
addTexture("floor", "textures/floor.jpg");
addTexture("red", "textures/red.jpg");

AbstractEntity[] list = new AbstractEntity[3];

list[0] = ModelUtil.loadModelMD2(getWorld(), "alita/tris", 0, -90, 0,
0.9f);
list[0].setTexture("alita2");
setCurrent(list[0]);
Animation run = list[0].getAnimationSequence();
anim = run.createSubSequence("run");

list[1] = new AbstractEntity(PlaneUtil.getPlane("floor", 20, 300),
getWorld());
list[1].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

list[2] = new AbstractEntity(Primitives.getCube(50), getWorld());
list[2].setTexture("red");
list[2].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

addObjects(list);
PositionUtil.placeOver(list[0], 0, 0);
PositionUtil.placeOver(list[2], -50, -50);

CameraUtil.setCameraLookingFromTop(getCamera(), list[0]);

LightUtil.addDefaultLight(getWorld());
addFPSListener(this);
Config.tuneForOutdoor();
Logger.setLogLevel(Logger.LL_ONLY_ERRORS);
}
Title: collision basics
Post by: athanazio on December 10, 2006, 05:16:55 am
errr
I solved the problem (at least I think I solved ...)
 
at the code

Code: [Select]

int collisionObject = w.checkCollision(getTransformedCenter(), where, 5 );


I increased the distance of the colision check from "5" to "25" and now my character lost its "ghost" powers ... ehhehehe

so it become :


Code: [Select]

int collisionObject = w.checkCollision(getTransformedCenter(), where, 25 );
Title: collision basics
Post by: cyberkilla on December 10, 2006, 06:04:13 pm
Good job:D
Title: collision basics
Post by: EgonOlsen on December 12, 2006, 09:38:38 pm
But remember that there are two other collision detection schemes, ellipsoid and spherical. The "manual" tells you more about them and when to use them.
Title: collision basics
Post by: athanazio on December 12, 2006, 09:40:53 pm
thanks !
but this one worked very fine ...
I'm in trouble now with the terrain creation hehehe