- Home /
Position from rotation problem.
I have a question I searched about and couldn't find. Sorry if there is already an answer. So, I have a GameObjet that is a wall that can have a rotation over the Y axis. In the script of this object, I have a node that can move around ( technically the player ). I want to find the position in X,Y,Z relative of the wall to the node. It already works if the Y rotation is 0. With those informations I want to display another node that is symtrical to the node on the other side of the wall. But I don't want it to be like a mirror. Right on one side of the wall is also right on the other side. I can show my code and I also know where I need to change the code, because it's already working, but not when I change the Y angle. Sorry but my variables are in french. Thanks for any help.
var cameraRelativeMur = objMurLiaison.transform.InverseTransformPoint( objCameraJoueur.transform.position );
cameraRelativeMur = cameraRelativeMur + Vector3( 0, -1 * cameraRelativeMur.y, -1 * cameraRelativeMur.y );
print( 'rel : ' + cameraRelativeMur );
// The 3 next lines are the one to change
// À modifer pour être en lien avec la rotation
var distanceX = 1 * ( positionPointMur.x - objCameraJoueur.transform.position.x );
var distanceY = 1 * ( positionPointMur.y - objCameraJoueur.transform.position.y );
var distanceZ = 1 * ( positionPointMur.z - objCameraJoueur.transform.position.z );
print( 'abs : (' + distanceX + ',' + distanceY + ',' + distanceZ + ')' );
var distXRel = ( distanceX * objMurLiaison.transform.right );
var distYRel = ( distanceY * objMurLiaison.transform.forward );
var distZRel = ( distanceZ * objMurLiaison.transform.up );
var distRel = distXRel + distYRel + distZRel;
transform.position = objMurLiaison.transform.position + distRel;
var directionSym = -1 * ( ( nodeObjCameraJoueur.transform.position ) - objCameraJoueur.transform.position );
directionSym -= Vector3( 0, directionSym.y * 2, 0 );
transform.rotation = Quaternion.LookRotation(directionSym);
Answer by robertbu · Sep 30, 2014 at 03:39 AM
If your wall is symmetrical around the pivot, can't you just rotate 180 degrees. That is, you place your second 'node' at the same position as the first and then do:
transform.RotateAround(wall.position, wall.up, 180);
You sir, are a great sir! It worked! But at first it wasn't doing so because I forgot that I rotated the wall on the X axis because it was a plane. So, the axis argument in the RotateAround function you wrote what in fact forward not up.
If you are using planes for walls, consider changing to Quads. A plane has 121 vertices and 200 triangles. A Quad has 4 vertices and 2 triangles. In addition, a Quad is vertical when the rotation is (0,0,0).
Well, polygon economy, won't say no to it. Thanks. I didn't know that the sides worked like a plane ( the normals ).