- Home /
object rotation to another vector not changing
Hi again everyone sorry to repeat a question but im still stuck and pulling my hair out over this one
this script works but it doesnt update when the object holding the script rotates.
basically i what i need is when the player is behind the object i want one part of the texture, to the left of the player show another part, in front of player another part etc etc
now as i said this script does work if the object stays facing one direction but the object will be moving and rotating so i need the back to always be at his back etc any help or more efficient way of doing this much appreciated
function Update ()
{
var toTarget = (referenceCamera.transform.position - transform.position).normalized;
if(toTarget.x > SpriteAnglesMin[0].x && toTarget.x < SpriteAnglesMax[0].x && toTarget.z > 0){
ObjectMesh.renderer.material.SetTextureOffset("_MainTex", Vector2(TextureCoordsX[0],0));
}
if(toTarget.x > SpriteAnglesMin[0].x && toTarget.x < SpriteAnglesMax[0].x && toTarget.z < 0) {
ObjectMesh.renderer.material.SetTextureOffset("_MainTex", Vector2(TextureCoordsX[2],0));
}
if(toTarget.z > SpriteAnglesMin[0].z && toTarget.z < SpriteAnglesMax[0].z && toTarget.x < 0){
ObjectMesh.renderer.material.SetTextureOffset("_MainTex", Vector2(TextureCoordsX[1],0));
}
if(toTarget.z > SpriteAnglesMin[0].z && toTarget.z < SpriteAnglesMax[0].z && toTarget.x > 0) {
ObjectMesh.renderer.material.SetTextureOffset("_MainTex", Vector2(TextureCoordsX[3],0));
}
}
Formatted your code to be readable.
Please ensure that your code has proper inlining before you post it.
apologies will note that for next time, any advice in relation to my question?
Your answer
![](https://koobas.hobune.stream/wayback/20220613175909im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Wheel Collider Rotation Problem 0 Answers
problem with object rotation 1 Answer
How to rotate object slowly on only Z axis 2 Answers
Rotation problem 1 Answer
rotation x changes all angles? 3 Answers