by default a camera doesn't act on setRotation(...) !!!
that's why the new function bindTargetAndRotation() was added, so a camera does act on setRotation() now if target and rotation are bind...
but you also use setTarget() and setRotation() on the camera, so the question is what function should the camera react on !?!?!
use either one of them and not both !!!
and of course use bindTargetAndRotation() first if you want to use setRotation() !!!
Now the problem is other, the car sometimes looses the focus. I mean I don't see all the car. So, do I need the setTarget() function to avoid this? But how I implement it with the setRotation also?
cdesseno wrote:Now the problem is other, the car sometimes looses the focus. I mean I don't see all the car.
what do you mean ???
does it vanish ???
maybe it's a culling problem, try to set another culling mode for the car (look for setAutomaticCulling(...) )...
cdesseno wrote:So, do I need the setTarget() function to avoid this? But how I implement it with the setRotation also?
you can use either methode you want, there should be no difference in the result, just the handling differs...
I'm pretty sure that the problem that you're having is because the camera is rotating around it's Y axis. What you probably want is for the camera to rotate around the vehicle. i.e., you want the vehicle to stay in the same spot on the screen and the camera should stay 'behind' it, right?
If so, you're going to need some more logic to put the camera in the right spot with the right rotation. There was some code that was posted in the past for a fancy chase camera. You might want to use the search feature to find it.
what about setting the camera as a child of the car ???
then you don't need to set it's rotation/target and position, it always will follow your car...
Sort of. I really doubt that he wants the camera to follow the car as if it were mounted rigidly from a transparent boom sticking out of the rear of the car.
He probably wants some smoothing so that if the user makes a hard turn you would see the side of the car for a few seconds, and then the camera would slowly rotate into position behind the car again, based on the speed of the car. This is how all modern driving/riding games that I've seen behave.
vitek wrote:Sort of. I really doubt that he wants the camera to follow the car as if it were mounted rigidly from a transparent boom sticking out of the rear of the car.
He probably wants some smoothing so that if the user makes a hard turn you would see the side of the car for a few seconds, and then the camera would slowly rotate into position behind the car again, based on the speed of the car. This is how all modern driving/riding games that I've seen behave.
1:
attach a empty scenenode as a child behind the car. Then every frame u set the Target of ur camera to your car and u move the camera itself towards the attached scenenode. either with a constant speed or depending to the distance (ofcourse it should be always time depended movement...never frame based)
2:
U could make the nessesary calculations yourself without using an extra scenenode. that pretty easy as well. You define a vector as pointing back in reference to the center of the car. then u apply the rotation of the car to that vector. after that u have the same position as if u would attach a scenenode. then simply do as in 1.
These two methods might look a little strange bc sometime the camera will move through the car when turning hard and the cam speed isn't high enough.
To solve that i have suggestion number 3
3:
Because ur car will only rotate around the Y-Axis u can define a rotation ring ring using polar cordinates with y=0 or any value u want. Then simply set the Car Y rotation to that rotation ring with smoth interpolation. Thats probably the nicest method.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.