how to make a object rotate towards a position in 2d unity

 Vector3 targ = staticCompassTarget.transform.position;
 targ.z = 0f; 
 Vector3 objectPos = transform.position;  
 targ.x = targ.x - objectPos.x;  
 targ.y = targ.y - objectPos.y;      
 float angle = Mathf.Atan2(targ.y, targ.x) * Mathf.Rad2Deg;   
 transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to rotate to an object to a point unity 2d rotate object to move towards direction 2d unity rotate towards direction 2d unity rotate towards 2d unity rotate 2d object based on direction how to rotate an object unity 2d once how to rotate an object unity 2d unity how to make an object rotate around another 2d make a 2d object rotate towards another rotate towards movemtn directiuon unity 2d unity 2d rotate towards object unity how rotate towards object 2d unity how to slowly rotate towards object 2d rotate object to mouse position unity 2d rotate gameobject towards point 2d unity rotate object towards point 2d Rotate Towards Mouse or Object in unity 2D Rotate or Aim Towards Mouse or Object in unity 2D unity 2d rotate object to mouse position unity 2d how to rotate around object how to make a 2d object rotate in unity unity 2d rotate object towards object how to rotate objects in the direction of another unity 2d how to make an object rotate around another object 2d in c# unity unity how to get something in 2d to slowly rotate to something how to rotate a gameobject in unity 2d how to make an object rotate towards the mouse in unity 2d unity rotate object around a point 2d unity 2d rotate towards direction how to find an object and rotate towards it in unity 2d how to rotate object in unity 2d unity 2d object rotate around itself how to make a 2d gameobject always rotate in unity unity 2d rotate towards mouse Rotate Towards Mouse Unity 2D how to rotate a 2d object in unity unity 2d rotate object around point how to change rotate of object in unity 2d with script unity how to make an object rotate around a 2d point how to rotate an object in unity 2d unity rotate towards mouse 2d how to rotate 2d object around itself unity unity how to make a gameobject rotate toward a point 2d how to make an object rotate to look at something unity 2d unity 2d rotate towards rotate 2d object to look at point unity set speed 2d object rotate to gravity unity make object rotate towards another object unity 2d slowly make object rotate towards another object unity 2d make object rotate towards other object unity 2d rotate 2d object to look at point unity how to rotate object towards object unity 2D how to smoothly rotate an object towards a specific position unity 2d unity how to rotate towards object 2d how do you rotate an object in unity 2d unity rotate towards point 2d unity rotate towards mouse object 2d how to rotate unity 2d unity 2d top down movement rotate in direction unity 2d rotate object towards position rotate object unity 2d towards other object how to rotate a object facing another object unity 2D rotate towards unity 2d unity rotate towards object 2d unity 2d rotate object to direction of mouse rotate object shortest way in unity unity 2d rotate object by 90 degrees unity 2d grass rotate towards direction unity get rotate towards point 2d
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source