Scaling and Following FancyCar Model

No one has responded to my original thread, and I have updated information, so I decided to make this new one.



I have implemented the FancyCar code into my project and I really like it. There are a couple of issues that should have quick answers:


  1. When I scale the model (player.scale(3)), the entire model scales, including the wheels, but the wheels are located near the center of the model instead of where they should be. I'm sure I need to apply a translation to each of the wheel nodes, but I want to know if there is a simpler way first.


  2. I am trying to get the camera to follow the car. I can position the camera behind the car, but I can't get the camera to rotate as the car rotates. I don't have much experience with Quaternions, which are used for the rotation, but I have this in my program:

Quaternion carRotation = car.getPlayer().getLocalRotation();
cam.setRotation(carRotation.fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y));


I know the problem resides in this code, so I'm probably guessing I will have to change these two lines to get the camera to rotate properly.

I am trying to use the CameraNode and CameraControl classes, but I cannot get the camera to follow the car. I use getPlayer() for the spatial to follow, but when I output getPlayer().getLocalTranslation() (or getWorldTranslation()), I get all zeroes. Is there some way to access the world coordinates of the car while being able to follow it, while having the chassis and wheels scale properly?

Thanks!

Have you tried player.setLocalScale()?

That's what is used in the Flag Rush Tutorial on the forceFieldFence node.


Quaternion carRotation = car.getPlayer().getLocalRotation();
cam.setRotation(carRotation.fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y));


You're getting the rotation of the car correctly, for the most part (consider using world rotation).
When you set it on the camera, you're modifying the rotation you just got in the process, instead of doing that, just set it directly (cam.setRotation(carRotation.clone())).
Momoko_Fan said:


Quaternion carRotation = car.getPlayer().getLocalRotation();
cam.setRotation(carRotation.fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y));


You're getting the rotation of the car correctly, for the most part (consider using world rotation).
When you set it on the camera, you're modifying the rotation you just got in the process, instead of doing that, just set it directly (cam.setRotation(carRotation.clone())).


Here is the new code that I am using for rotation. The camera does rotate in the same direction as the car, but not as much. I'm not sure why though.

cam.setRotation(car.chasis.getWorldRotation().add(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y)));



EDIT: I have fixed the rotation problem. Simply replacing "add" with "mult" worked! (See http://www.jmonkeyengine.com/forum/index.php?topic=14789.msg105860#msg105860)

Also, the reason I use .fromAngleAxis() is because without it the camera works fine, but it is facing behind the car (perhaps something to do with the fact that the car actually goes backwards). So I have to rotate the camera 180 degrees in addition to the rotation of the car, so that the camera will face the "front" of the car.

HeroHero said:

Have you tried player.setLocalScale()?
That's what is used in the Flag Rush Tutorial on the forceFieldFence node.


I am assuming you are referring to this page (http://www.jmonkeyengine.com/wiki/doku.php/adding_a_chase_camera).  I would like to use JBullet physics to control the car, if I can get these problems resolved.

Still, I have tried that code, but it has no effect on the car. I add it right after player is initialized to before/after it is added to the physics space, but the model is not larger.

Thanks for the suggestions guys. If you want me to debug some values, let me know.