RayTest problem

I was using this code for the game to see where is the point at which fired bullet will be destroyed.
[java]
List<PhysicsRayTestResult> rayTest = bulletState.getPhysicsSpace().rayTest(vecStart, vecEnd);
if (rayTest.size() > 0) {
for (Object object : rayTest) {
//distance to next collision
PhysicsRayTestResult getObject = (PhysicsRayTestResult) object;
float fl = getObject.getHitFraction();
PhysicsCollisionObject collisionObject = getObject.getCollisionObject();
Spatial thisSpatial = (Spatial) collisionObject.getUserObject();

[/java]

I’ve added characters and walls to physical space and they are shown in debug mode. The bullet always collide with the characters, but rarely with wall. Does anybody have idea what had I done to somehow bypass this rayTest to not work correctly?

I tested with printing of points you use:

VecStart (-3.0256988E-8, -7.144001E-4, 3.6159689E-9)
VecEnd (-3.0256988E-8, -7.144001E-4, 70.0)

I guess Y should = 1.0.

I think this is because you get position of a Geometry.
But you should take the position of physics body.

I dunno remember but possibly i got physicsBody.GetPhysicsLocation(). There Y=1.0.

As workaround you can fix it in your code like this:
bornPlace = new Vector3f(origin).setY(1.0f);

1 Like

It is working. :smiley:

@Tihomir said: It is working. :D

Character movement is still buggy. You need to fix it before AI.

Press W, Release W, Press D, Release D, Press D, Release D, Press D, Release D, Press D, Release D - Charcter will move.

This should be fixed as this is a bug.

@Tihomir i commited the bullet fix Bullet fix: Clone position of the character, set Y coordinate the sam… · QuietOne/MonkeyBrainsDemoGames@f71b5ac · GitHub

I set Y of the character’s position. This will be much better for future.
Also i clone the position of the character so that there would be less issues.