- Home /
Transforming a moving 3D Object is altering the direction
I am creating a Braitenberg simulation and am trying to implement a screen wrap function. My vehicles are cubes with cylinders attached with hinge joints to create wheels, the back wheels are powered by a motor to produce movement that varies depending on environmental factors.
My issue is that when I transform my vehicle components on collision with a wall, the vehicle jerks and changes direction of movement after transforming. See image below.
I am currently using this code to transform the body and wheels of the vehicle within my vehicleController script, I feel the issue may be that i am transforming them individually but I do not know how else to do it as the vehicle parent transform does not hold the current position.
Vector3 flip = transforms[1].position;
Debug.Log(flip);
flip.z = -(flip.z);
Debug.Log(flip);
transforms[1].position = flip;
for(int i = 4; i < 8; i++)
{
flip = transforms[i].position;
flip.z = -(flip.z);
transforms[i].position = flip;
}
With transform[1] being the body and transform[4-7] being the wheels.
Thanks