VehicleControl.getPhysicsLocation() and cube distance calculation?

Hey there. I have small problem with calculating the distance between two objects: Vehicle control type object and simple box shape. What I want to do is when the car reaches the box shape location on Z axis, the box will change color. Whenever I want to check the location of a car I’m using VehicleControl.getPhysicsLocation() method, but I don’t think it’s accurate as it’s always showing wrong vectors. Am I missing something here? Below is the screenshot of my implementation. The box should change to red when the car is directly below the cube, but it’s always the case that it changes before the car reaches the cube (as seen on screenshot). Any ideas?

Is your cube centred on the origin? and are you using its world translation? A testcase would be easiest to look at, as it could be a number of different things.

Hey wezrule - thanks for reply. This is the code I’m using to implement the cube:

[java]
signalShape = new Box(signalPosition, .1f, .1f, .1f);
signalGeometry = new Geometry(“signal”, signalShape);
setSignalMaterialToGreen();
signalGeometry.setLocalTranslation(signalPosition);
signalGeometry.setShadowMode(ShadowMode.CastAndReceive);
[/java]

The signalPosition is the vector at which the cube is situated. When I’m checking it with System.out.prinln() it show the correct location. I’m returning the cube location with signalGeometry.getWorldTranslation() method. I’m kinda of a noob in 3D programming so please bear with me. And what do you mean by saying “cube centered on the origin”? Thanks a lot for responding!

Your box constructor should use (Vector3f.Zero, 0.1f, 0.1f, 0.1f), your box mesh is offset

1 Like

wezrule - you’re a genius!! Problem solved! Thank you so much!