Hey forum, I am building a prototype for a client, and in it I am having a car zip around a track, Because the client does not want the car to crash into anything, we are controlling the movements with a .fbx from Blender. I have built a project that takes the data from each frame of the animation and then binds that to an array that I can then apply to a model in my player. As I am trying to make the car as realistic as possible I have the wheels responding to the change in vector of each frame of the car’s movement. I have then contained with a parent entity to that I can rotate them around the axle as well as turn them in relation to the car’s movements. I have the chassis of the car contained in a parent entity as well so that I can apply intertia to the car as it turns.
All the parts of the car are contained in a parent entity that has the animation player component attached that moves this parent around the track.
Wha I am running into, is that I am trying to rotate the chassis based on the inertia of the turn. I am using rotateLocal(0,difference,0). The translation from Blender requires that the .dae model be rotated in the parent container for the chassis by 90 degrees to fit the axis change that occurs going from Blender to PC.
What I would like to do is set the model to a specific rotation that is the difference of change each frame off of 0, but what it is doing is actually rotating by rather than rotating to. Has anyone run into this before and if so could you please offer some advice?
var change = Math.atan2(this.lastPos[2] - newPos[2],this.lastPos[0] - newPos[0]) * 180 / Math.PI;
var directedAngle = (Math.atan2(this.lastPos[2], this.lastPos[0]) - Math.atan2(newPos[2], newPos[0])) * 180 / Math.PI;
if(directedAngle < 0 ){
console.log("turn right");
}
if(directedAngle > 0 ){
console.log("turn left");
}
this.lastPos = [newPos[0],newPos[1],newPos[2]];
this.wheel1.rotateLocal(0,-directedAngle,0);
this.wheel2.rotateLocal(0,-directedAngle,0);
this.bodyContainer.rotateLocal(0,-directedAngle,0);