- Home /
Rotate my player around my locked target.
I'm trying to make my player rotate around the target when I press a button to focus on it. I get it to work when I have my rigidbody is kinematic. However I want to be able to achieve the same thing without kinematic on so that I can interact and walk into objects. I asume the rb.MoveRotation is the function I should be using for this. However I cannot find anything that makes me understand how to apply it in my current situation. Any help is appriciated.
 public Rigidbody rb;
 void Awake () {
     rb = GetComponent<Rigidbody>();       
 }
         if (lStickPressed)
             {
             //Debug.Log("Locked Onto: " + tar);
             Vector3 tarPos = new Vector3(eFinder.tar.transform.position.x, eFinder.tar.transform.position.y, eFinder.tar.transform.position.z);
             rb.transform.LookAt(tarPos);
 
             //old rotation with rigidbody is kinematic
             Quaternion q = transform.rotation;
             q.eulerAngles = new Vector3(0, q.eulerAngles.y, q.eulerAngles.z);
             transform.rotation = q;
 
             // Movement
             Vector3 movementf = transform.TransformDirection(new Vector3(hAxis, 0, vAxis) * speed * Time.deltaTime);
             rb.MovePosition(transform.position + movementf * speed * Time.deltaTime);        
         }
Answer by TobySk · May 01, 2018 at 06:56 PM
Managed to figure it out. If anyone googles this in the future here's my solution:
             Vector3 tarPos = new Vector3(eFinder.tar.transform.position.x, eFinder.tar.transform.position.y, eFinder.tar.transform.position.z);
             rb.transform.LookAt(tarPos);
 
             //TEst
             Quaternion q = rb.rotation;
             q.eulerAngles = new Vector3(0, q.eulerAngles.y, q.eulerAngles.z);
             rb.MoveRotation(q); 
 
             // Movement
             rb.MovePosition(transform.position + movementf * speed * Time.deltaTime);        
Your answer
 
 
             Follow this Question
Related Questions
How do I implement both Rigidbody.MovePosition and Rigidbody.MoveRotation simultaneously? 1 Answer
Rigidbody goes wonky after collision 0 Answers
Rotate player (rigidbody) towards his movement 2 Answers
How to make a RigidBody not go into ground when tilted foward? 2 Answers
What is the most accurate method of calculating total rotations of a rigidbody? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                