Need Help With Having Player look at an object while stationary.
So basically Here is my problem, I have a script that makes my players spine rotate whatever direction my target object is facing this works properly but I also have a separate script to make the object move where ever the mouse position is on the screen according to the objects world position or camera position I am not sure exactly how these scripts work so I just believe this to b true as I am new to C#. anyhow this works The object moves where ever the mouse goes and the player looks in the direction of the object but the issue is that the player is flying towards the object, and that's not what I want, the indented behavior is to have the object move where ever the mouse is and the players spine to turn in the direction of that object while staying stationary. can anyone help me with this?
here is my code for rotating the spine in whatever direction of the target object:
public Transform Target;
public Vector3 Offset;
Animator anim;
Transform Spine;
void Start()
{
anim = GetComponent<Animator>();
Spine = anim.GetBoneTransform(HumanBodyBones.Spine);
}
void LateUpdate()
{
Spine.LookAt(Target.position);
Spine.rotation = Spine.rotation * Quaternion.Euler(Offset);
}
}
here is my code for Moving the object according to mouse pos and world space:
void Update()
{
Vector3 temp = Input.mousePosition;
temp.z = 20f; // Set this to be the distance you want the object to be placed in front of the camera.
this.transform.position = Camera.main.ScreenToWorldPoint(temp);
}
}