How to rotate object counterclockwise?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I can't find a single answer to this question. I apologize if this is a duplicate post but I can't find anything.



I'm trying to animate an object counterclockwise in a 2D game in Unity. I assume there must be a simple one or two line code to do this, but I can't figure it out. Everything I've read says that rotating clockwise is easy but that Unity makes counter-clockwise rotation more complicated?










share|improve this question


















  • 3





    If you can rotate clockwise, then simply negate the angle to rotate counter-clockwise.

    – Nico Schertler
    Nov 16 '18 at 15:58


















1















I can't find a single answer to this question. I apologize if this is a duplicate post but I can't find anything.



I'm trying to animate an object counterclockwise in a 2D game in Unity. I assume there must be a simple one or two line code to do this, but I can't figure it out. Everything I've read says that rotating clockwise is easy but that Unity makes counter-clockwise rotation more complicated?










share|improve this question


















  • 3





    If you can rotate clockwise, then simply negate the angle to rotate counter-clockwise.

    – Nico Schertler
    Nov 16 '18 at 15:58














1












1








1








I can't find a single answer to this question. I apologize if this is a duplicate post but I can't find anything.



I'm trying to animate an object counterclockwise in a 2D game in Unity. I assume there must be a simple one or two line code to do this, but I can't figure it out. Everything I've read says that rotating clockwise is easy but that Unity makes counter-clockwise rotation more complicated?










share|improve this question














I can't find a single answer to this question. I apologize if this is a duplicate post but I can't find anything.



I'm trying to animate an object counterclockwise in a 2D game in Unity. I assume there must be a simple one or two line code to do this, but I can't figure it out. Everything I've read says that rotating clockwise is easy but that Unity makes counter-clockwise rotation more complicated?







c# unity3d






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 15:54









NomadicBinaryNomadicBinary

275




275








  • 3





    If you can rotate clockwise, then simply negate the angle to rotate counter-clockwise.

    – Nico Schertler
    Nov 16 '18 at 15:58














  • 3





    If you can rotate clockwise, then simply negate the angle to rotate counter-clockwise.

    – Nico Schertler
    Nov 16 '18 at 15:58








3




3





If you can rotate clockwise, then simply negate the angle to rotate counter-clockwise.

– Nico Schertler
Nov 16 '18 at 15:58





If you can rotate clockwise, then simply negate the angle to rotate counter-clockwise.

– Nico Schertler
Nov 16 '18 at 15:58












1 Answer
1






active

oldest

votes


















1














Before we get into the coding bits of this question.
You first need to understand the logic behind what you want to achieve.
counter clockwise is just the angle you want to rotate but negated (-).



To rotate in 2D around an object you can simply do:



using UnityEngine;

public class Example : MonoBehaviour
{
void Update()
{
// Spin the object around the world origin at 20 degrees/second.
transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
}


In 2D the Axis of rotation will simply become Vector3.back or Vector3.forward depending on the direction you want to rotate



Example from: https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html



And as user “Programmer” pointed out: transform.Rotate will do the trick if you’re not looking to rotate the object around another object.



using UnityEngine;

public class ExampleClass : MonoBehaviour
{
void Update()
{
// Rotate the object around its local X axis at 1 degree per second
transform.Rotate(Vector3.right * Time.deltaTime);

// ...also rotate around the World's Y axis
transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
}
}


Example from: https://docs.unity3d.com/ScriptReference/Transform.Rotate.html



Since OP has clarified even further what he wants to achieve. I'll leave these images for reference:



z = 0z = -10



With that said: try:



 Vector3 direction = player.transform.position - iss.transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * mathf.Rad2Deg;
iss.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);





share|improve this answer


























  • OP wants to rotate an object not rotate object around another object...transform.Rotate is more appropriate here than transform.RotateAround

    – Programmer
    Nov 16 '18 at 16:28











  • @Programmer updated the answer.

    – Joel
    Nov 16 '18 at 16:43











  • I'm sorry if I didn't clarify this in my original post, but I do know about transform.Rotate(Vector3.right * Time.deltaTime), but as you said that rotates around the x axis, or y for up. My problem is since it's a 2D program, I need to rotate it along the Z axis. What can I do to rotate it counterclockwise on the Z axis?

    – NomadicBinary
    Nov 16 '18 at 19:09











  • I left two images for reference on how the Z-axis affects the scene in 2D and a solution below the images.

    – Joel
    Nov 22 '18 at 13:58













  • @NomadicBinary Please mark this as the answer if it helped you solve your problem or explain what i can change to help you further.

    – Joel
    Jan 15 at 10:14














Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341309%2fhow-to-rotate-object-counterclockwise%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Before we get into the coding bits of this question.
You first need to understand the logic behind what you want to achieve.
counter clockwise is just the angle you want to rotate but negated (-).



To rotate in 2D around an object you can simply do:



using UnityEngine;

public class Example : MonoBehaviour
{
void Update()
{
// Spin the object around the world origin at 20 degrees/second.
transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
}


In 2D the Axis of rotation will simply become Vector3.back or Vector3.forward depending on the direction you want to rotate



Example from: https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html



And as user “Programmer” pointed out: transform.Rotate will do the trick if you’re not looking to rotate the object around another object.



using UnityEngine;

public class ExampleClass : MonoBehaviour
{
void Update()
{
// Rotate the object around its local X axis at 1 degree per second
transform.Rotate(Vector3.right * Time.deltaTime);

// ...also rotate around the World's Y axis
transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
}
}


Example from: https://docs.unity3d.com/ScriptReference/Transform.Rotate.html



Since OP has clarified even further what he wants to achieve. I'll leave these images for reference:



z = 0z = -10



With that said: try:



 Vector3 direction = player.transform.position - iss.transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * mathf.Rad2Deg;
iss.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);





share|improve this answer


























  • OP wants to rotate an object not rotate object around another object...transform.Rotate is more appropriate here than transform.RotateAround

    – Programmer
    Nov 16 '18 at 16:28











  • @Programmer updated the answer.

    – Joel
    Nov 16 '18 at 16:43











  • I'm sorry if I didn't clarify this in my original post, but I do know about transform.Rotate(Vector3.right * Time.deltaTime), but as you said that rotates around the x axis, or y for up. My problem is since it's a 2D program, I need to rotate it along the Z axis. What can I do to rotate it counterclockwise on the Z axis?

    – NomadicBinary
    Nov 16 '18 at 19:09











  • I left two images for reference on how the Z-axis affects the scene in 2D and a solution below the images.

    – Joel
    Nov 22 '18 at 13:58













  • @NomadicBinary Please mark this as the answer if it helped you solve your problem or explain what i can change to help you further.

    – Joel
    Jan 15 at 10:14


















1














Before we get into the coding bits of this question.
You first need to understand the logic behind what you want to achieve.
counter clockwise is just the angle you want to rotate but negated (-).



To rotate in 2D around an object you can simply do:



using UnityEngine;

public class Example : MonoBehaviour
{
void Update()
{
// Spin the object around the world origin at 20 degrees/second.
transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
}


In 2D the Axis of rotation will simply become Vector3.back or Vector3.forward depending on the direction you want to rotate



Example from: https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html



And as user “Programmer” pointed out: transform.Rotate will do the trick if you’re not looking to rotate the object around another object.



using UnityEngine;

public class ExampleClass : MonoBehaviour
{
void Update()
{
// Rotate the object around its local X axis at 1 degree per second
transform.Rotate(Vector3.right * Time.deltaTime);

// ...also rotate around the World's Y axis
transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
}
}


Example from: https://docs.unity3d.com/ScriptReference/Transform.Rotate.html



Since OP has clarified even further what he wants to achieve. I'll leave these images for reference:



z = 0z = -10



With that said: try:



 Vector3 direction = player.transform.position - iss.transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * mathf.Rad2Deg;
iss.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);





share|improve this answer


























  • OP wants to rotate an object not rotate object around another object...transform.Rotate is more appropriate here than transform.RotateAround

    – Programmer
    Nov 16 '18 at 16:28











  • @Programmer updated the answer.

    – Joel
    Nov 16 '18 at 16:43











  • I'm sorry if I didn't clarify this in my original post, but I do know about transform.Rotate(Vector3.right * Time.deltaTime), but as you said that rotates around the x axis, or y for up. My problem is since it's a 2D program, I need to rotate it along the Z axis. What can I do to rotate it counterclockwise on the Z axis?

    – NomadicBinary
    Nov 16 '18 at 19:09











  • I left two images for reference on how the Z-axis affects the scene in 2D and a solution below the images.

    – Joel
    Nov 22 '18 at 13:58













  • @NomadicBinary Please mark this as the answer if it helped you solve your problem or explain what i can change to help you further.

    – Joel
    Jan 15 at 10:14
















1












1








1







Before we get into the coding bits of this question.
You first need to understand the logic behind what you want to achieve.
counter clockwise is just the angle you want to rotate but negated (-).



To rotate in 2D around an object you can simply do:



using UnityEngine;

public class Example : MonoBehaviour
{
void Update()
{
// Spin the object around the world origin at 20 degrees/second.
transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
}


In 2D the Axis of rotation will simply become Vector3.back or Vector3.forward depending on the direction you want to rotate



Example from: https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html



And as user “Programmer” pointed out: transform.Rotate will do the trick if you’re not looking to rotate the object around another object.



using UnityEngine;

public class ExampleClass : MonoBehaviour
{
void Update()
{
// Rotate the object around its local X axis at 1 degree per second
transform.Rotate(Vector3.right * Time.deltaTime);

// ...also rotate around the World's Y axis
transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
}
}


Example from: https://docs.unity3d.com/ScriptReference/Transform.Rotate.html



Since OP has clarified even further what he wants to achieve. I'll leave these images for reference:



z = 0z = -10



With that said: try:



 Vector3 direction = player.transform.position - iss.transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * mathf.Rad2Deg;
iss.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);





share|improve this answer















Before we get into the coding bits of this question.
You first need to understand the logic behind what you want to achieve.
counter clockwise is just the angle you want to rotate but negated (-).



To rotate in 2D around an object you can simply do:



using UnityEngine;

public class Example : MonoBehaviour
{
void Update()
{
// Spin the object around the world origin at 20 degrees/second.
transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
}


In 2D the Axis of rotation will simply become Vector3.back or Vector3.forward depending on the direction you want to rotate



Example from: https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html



And as user “Programmer” pointed out: transform.Rotate will do the trick if you’re not looking to rotate the object around another object.



using UnityEngine;

public class ExampleClass : MonoBehaviour
{
void Update()
{
// Rotate the object around its local X axis at 1 degree per second
transform.Rotate(Vector3.right * Time.deltaTime);

// ...also rotate around the World's Y axis
transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
}
}


Example from: https://docs.unity3d.com/ScriptReference/Transform.Rotate.html



Since OP has clarified even further what he wants to achieve. I'll leave these images for reference:



z = 0z = -10



With that said: try:



 Vector3 direction = player.transform.position - iss.transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * mathf.Rad2Deg;
iss.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 13:55

























answered Nov 16 '18 at 16:04









JoelJoel

1,2611326




1,2611326













  • OP wants to rotate an object not rotate object around another object...transform.Rotate is more appropriate here than transform.RotateAround

    – Programmer
    Nov 16 '18 at 16:28











  • @Programmer updated the answer.

    – Joel
    Nov 16 '18 at 16:43











  • I'm sorry if I didn't clarify this in my original post, but I do know about transform.Rotate(Vector3.right * Time.deltaTime), but as you said that rotates around the x axis, or y for up. My problem is since it's a 2D program, I need to rotate it along the Z axis. What can I do to rotate it counterclockwise on the Z axis?

    – NomadicBinary
    Nov 16 '18 at 19:09











  • I left two images for reference on how the Z-axis affects the scene in 2D and a solution below the images.

    – Joel
    Nov 22 '18 at 13:58













  • @NomadicBinary Please mark this as the answer if it helped you solve your problem or explain what i can change to help you further.

    – Joel
    Jan 15 at 10:14





















  • OP wants to rotate an object not rotate object around another object...transform.Rotate is more appropriate here than transform.RotateAround

    – Programmer
    Nov 16 '18 at 16:28











  • @Programmer updated the answer.

    – Joel
    Nov 16 '18 at 16:43











  • I'm sorry if I didn't clarify this in my original post, but I do know about transform.Rotate(Vector3.right * Time.deltaTime), but as you said that rotates around the x axis, or y for up. My problem is since it's a 2D program, I need to rotate it along the Z axis. What can I do to rotate it counterclockwise on the Z axis?

    – NomadicBinary
    Nov 16 '18 at 19:09











  • I left two images for reference on how the Z-axis affects the scene in 2D and a solution below the images.

    – Joel
    Nov 22 '18 at 13:58













  • @NomadicBinary Please mark this as the answer if it helped you solve your problem or explain what i can change to help you further.

    – Joel
    Jan 15 at 10:14



















OP wants to rotate an object not rotate object around another object...transform.Rotate is more appropriate here than transform.RotateAround

– Programmer
Nov 16 '18 at 16:28





OP wants to rotate an object not rotate object around another object...transform.Rotate is more appropriate here than transform.RotateAround

– Programmer
Nov 16 '18 at 16:28













@Programmer updated the answer.

– Joel
Nov 16 '18 at 16:43





@Programmer updated the answer.

– Joel
Nov 16 '18 at 16:43













I'm sorry if I didn't clarify this in my original post, but I do know about transform.Rotate(Vector3.right * Time.deltaTime), but as you said that rotates around the x axis, or y for up. My problem is since it's a 2D program, I need to rotate it along the Z axis. What can I do to rotate it counterclockwise on the Z axis?

– NomadicBinary
Nov 16 '18 at 19:09





I'm sorry if I didn't clarify this in my original post, but I do know about transform.Rotate(Vector3.right * Time.deltaTime), but as you said that rotates around the x axis, or y for up. My problem is since it's a 2D program, I need to rotate it along the Z axis. What can I do to rotate it counterclockwise on the Z axis?

– NomadicBinary
Nov 16 '18 at 19:09













I left two images for reference on how the Z-axis affects the scene in 2D and a solution below the images.

– Joel
Nov 22 '18 at 13:58







I left two images for reference on how the Z-axis affects the scene in 2D and a solution below the images.

– Joel
Nov 22 '18 at 13:58















@NomadicBinary Please mark this as the answer if it helped you solve your problem or explain what i can change to help you further.

– Joel
Jan 15 at 10:14







@NomadicBinary Please mark this as the answer if it helped you solve your problem or explain what i can change to help you further.

– Joel
Jan 15 at 10:14






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341309%2fhow-to-rotate-object-counterclockwise%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine