Unity 3D - rotating gameobject without rotating axis
Hope my title summarises my problem. I have a rocket on a 2d game that only moves horizontally across the screen. I want it to rotate towards the players finger (the direction of movement), but cannot find a way to rotate the object without rotating the whole axis it moves on. I simply need it to seem like it has turned, but it should keep moving along the x. How can I go about this?
void Start () {
//scoreT = GetComponent<TextMeshProUGUI> ();
gameSpeed = 1;
score = 0;
Rigidbody2D rb2d = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
float MoveHorizontal = Input.GetAxis ("Horizontal");
Vector2 Movement = new Vector2 (MoveHorizontal, 0.0f);
rb2d.rotation = Quaternion.Euler (0.0f, 0, 0f, rb2d.velocity.x * -tilt);
transform.Translate (MoveHorizontal * speed, 0, 0);
c# unity3d rotation
add a comment |
Hope my title summarises my problem. I have a rocket on a 2d game that only moves horizontally across the screen. I want it to rotate towards the players finger (the direction of movement), but cannot find a way to rotate the object without rotating the whole axis it moves on. I simply need it to seem like it has turned, but it should keep moving along the x. How can I go about this?
void Start () {
//scoreT = GetComponent<TextMeshProUGUI> ();
gameSpeed = 1;
score = 0;
Rigidbody2D rb2d = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
float MoveHorizontal = Input.GetAxis ("Horizontal");
Vector2 Movement = new Vector2 (MoveHorizontal, 0.0f);
rb2d.rotation = Quaternion.Euler (0.0f, 0, 0f, rb2d.velocity.x * -tilt);
transform.Translate (MoveHorizontal * speed, 0, 0);
c# unity3d rotation
add a comment |
Hope my title summarises my problem. I have a rocket on a 2d game that only moves horizontally across the screen. I want it to rotate towards the players finger (the direction of movement), but cannot find a way to rotate the object without rotating the whole axis it moves on. I simply need it to seem like it has turned, but it should keep moving along the x. How can I go about this?
void Start () {
//scoreT = GetComponent<TextMeshProUGUI> ();
gameSpeed = 1;
score = 0;
Rigidbody2D rb2d = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
float MoveHorizontal = Input.GetAxis ("Horizontal");
Vector2 Movement = new Vector2 (MoveHorizontal, 0.0f);
rb2d.rotation = Quaternion.Euler (0.0f, 0, 0f, rb2d.velocity.x * -tilt);
transform.Translate (MoveHorizontal * speed, 0, 0);
c# unity3d rotation
Hope my title summarises my problem. I have a rocket on a 2d game that only moves horizontally across the screen. I want it to rotate towards the players finger (the direction of movement), but cannot find a way to rotate the object without rotating the whole axis it moves on. I simply need it to seem like it has turned, but it should keep moving along the x. How can I go about this?
void Start () {
//scoreT = GetComponent<TextMeshProUGUI> ();
gameSpeed = 1;
score = 0;
Rigidbody2D rb2d = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
float MoveHorizontal = Input.GetAxis ("Horizontal");
Vector2 Movement = new Vector2 (MoveHorizontal, 0.0f);
rb2d.rotation = Quaternion.Euler (0.0f, 0, 0f, rb2d.velocity.x * -tilt);
transform.Translate (MoveHorizontal * speed, 0, 0);
c# unity3d rotation
c# unity3d rotation
edited Nov 21 '18 at 21:51
Mattattack
asked Nov 21 '18 at 9:00
MattattackMattattack
738
738
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
One thing you can do is to modify rigidbody.rotation
of your rocket rocket to make it tilt, when it moves, to one direction or to another. For example:
float tilt - 0.3f;
//In case you prefer the rotation in another axis you just need to modify the position of the rigidbody.velocity.x * -tilt
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
Since you didn't add any code I am not sure how you are moving your rocket, so I will post a generic code you will need to adapt depending on your own project:
public class PlayerController : MonoBehaviour
{
public float speed;
//The tild factor
public float tilt;
//The limit within the spaceship can move
public Boundary boundary;
void FixedUpdate ()
{
//You will need to capture the screen touchs of the user for the inputs
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
//Applying the movement to the GameObject
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
//To ensure the GameObject doesnt move outside of the game boundary
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
//Here is where you apply the rotation
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
}
}
As an aside, you are doing a space 2D game you may be interested in checking this tutorial:
https://unity3d.com/learn/tutorials/s/space-shooter-tutorial
I seem to be getting an error saying 'UnityEngine.Component' does not contain a definition for rotation. Any idea what I've done wrong? Thank you
– Mattattack
Nov 21 '18 at 21:18
I have added the code to my question.
– Mattattack
Nov 21 '18 at 21:51
@Mattattack I think the problem is the Quaternion.Euler I posted is expecting a rigidbody, not a rigidbody2D... Try to add a rigidbody (not a 2D) to the gameobject, and then you can access that rigidbody component directly as in my code. That is, remove this: Rigidbody2D rb2d = GetComponent<Rigidbody2D> (); As far as I know the script will access directly the rigidbody component of the GameObject which it's attached to
– Ignacio Alorre
Nov 22 '18 at 7:19
I had added the rigidbody2D trying to get it to work. Without the rigidbody2D it still does not work. When I begin to type rigidbody, the auto complete has a line through it, it is not recognized.
– Mattattack
Nov 22 '18 at 16:52
@Mattattack But you should add the rigidbody as a component of the GameObject from the editor first, then you can access it from code. Can you list what are the components in the rocket GameObject? You can see them from the editor
– Ignacio Alorre
Nov 22 '18 at 20:29
|
show 4 more comments
What you want is to move your object in global/world space. As it seems the movement of your rocket is currently happening within local space. So when you rotate the rocket it's local coordinates are rotated as well. The world space coordinates are fixed and will never rotate when you change your rocket.
Here is another explanation at that.
You can also have a look at Transform.localPosition and Transform.position and see how your rocket behaves when using one or the other.
I've already tried setting my axis relative to the world and it seemed to have no effect, I may have done something wrong, but it still did not work.
– Mattattack
Nov 21 '18 at 9:41
add a comment |
You must move your object relative to the world and rotate locally.
So use Transform.position to move your object and Transform.LocalRotation to rotate it.
Or you can put the part that must rotate as a children of the object that translate, and rotate the children.
Can you explain how I can achieve this? I am failing to understand localRotation's properties.
– Mattattack
Nov 21 '18 at 11:33
you use Transform.LocalRotation has you use Transform.Rotation. The difference betwwen those two when you use Rotation it's de rotation of the object relative to the world When you use Local rotation it's relative to his parent.
– Samuel Thauvin Apouchkal
Nov 22 '18 at 14:06
add a comment |
You could make the sprite/renderer a child of the GameObject that is your rocket.
Then you can freely rotate the sprite/renderer around without changing the rotation you move the parent GameObject.
This is a hacky solution but it achieves the desired result.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408424%2funity-3d-rotating-gameobject-without-rotating-axis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
One thing you can do is to modify rigidbody.rotation
of your rocket rocket to make it tilt, when it moves, to one direction or to another. For example:
float tilt - 0.3f;
//In case you prefer the rotation in another axis you just need to modify the position of the rigidbody.velocity.x * -tilt
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
Since you didn't add any code I am not sure how you are moving your rocket, so I will post a generic code you will need to adapt depending on your own project:
public class PlayerController : MonoBehaviour
{
public float speed;
//The tild factor
public float tilt;
//The limit within the spaceship can move
public Boundary boundary;
void FixedUpdate ()
{
//You will need to capture the screen touchs of the user for the inputs
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
//Applying the movement to the GameObject
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
//To ensure the GameObject doesnt move outside of the game boundary
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
//Here is where you apply the rotation
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
}
}
As an aside, you are doing a space 2D game you may be interested in checking this tutorial:
https://unity3d.com/learn/tutorials/s/space-shooter-tutorial
I seem to be getting an error saying 'UnityEngine.Component' does not contain a definition for rotation. Any idea what I've done wrong? Thank you
– Mattattack
Nov 21 '18 at 21:18
I have added the code to my question.
– Mattattack
Nov 21 '18 at 21:51
@Mattattack I think the problem is the Quaternion.Euler I posted is expecting a rigidbody, not a rigidbody2D... Try to add a rigidbody (not a 2D) to the gameobject, and then you can access that rigidbody component directly as in my code. That is, remove this: Rigidbody2D rb2d = GetComponent<Rigidbody2D> (); As far as I know the script will access directly the rigidbody component of the GameObject which it's attached to
– Ignacio Alorre
Nov 22 '18 at 7:19
I had added the rigidbody2D trying to get it to work. Without the rigidbody2D it still does not work. When I begin to type rigidbody, the auto complete has a line through it, it is not recognized.
– Mattattack
Nov 22 '18 at 16:52
@Mattattack But you should add the rigidbody as a component of the GameObject from the editor first, then you can access it from code. Can you list what are the components in the rocket GameObject? You can see them from the editor
– Ignacio Alorre
Nov 22 '18 at 20:29
|
show 4 more comments
One thing you can do is to modify rigidbody.rotation
of your rocket rocket to make it tilt, when it moves, to one direction or to another. For example:
float tilt - 0.3f;
//In case you prefer the rotation in another axis you just need to modify the position of the rigidbody.velocity.x * -tilt
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
Since you didn't add any code I am not sure how you are moving your rocket, so I will post a generic code you will need to adapt depending on your own project:
public class PlayerController : MonoBehaviour
{
public float speed;
//The tild factor
public float tilt;
//The limit within the spaceship can move
public Boundary boundary;
void FixedUpdate ()
{
//You will need to capture the screen touchs of the user for the inputs
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
//Applying the movement to the GameObject
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
//To ensure the GameObject doesnt move outside of the game boundary
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
//Here is where you apply the rotation
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
}
}
As an aside, you are doing a space 2D game you may be interested in checking this tutorial:
https://unity3d.com/learn/tutorials/s/space-shooter-tutorial
I seem to be getting an error saying 'UnityEngine.Component' does not contain a definition for rotation. Any idea what I've done wrong? Thank you
– Mattattack
Nov 21 '18 at 21:18
I have added the code to my question.
– Mattattack
Nov 21 '18 at 21:51
@Mattattack I think the problem is the Quaternion.Euler I posted is expecting a rigidbody, not a rigidbody2D... Try to add a rigidbody (not a 2D) to the gameobject, and then you can access that rigidbody component directly as in my code. That is, remove this: Rigidbody2D rb2d = GetComponent<Rigidbody2D> (); As far as I know the script will access directly the rigidbody component of the GameObject which it's attached to
– Ignacio Alorre
Nov 22 '18 at 7:19
I had added the rigidbody2D trying to get it to work. Without the rigidbody2D it still does not work. When I begin to type rigidbody, the auto complete has a line through it, it is not recognized.
– Mattattack
Nov 22 '18 at 16:52
@Mattattack But you should add the rigidbody as a component of the GameObject from the editor first, then you can access it from code. Can you list what are the components in the rocket GameObject? You can see them from the editor
– Ignacio Alorre
Nov 22 '18 at 20:29
|
show 4 more comments
One thing you can do is to modify rigidbody.rotation
of your rocket rocket to make it tilt, when it moves, to one direction or to another. For example:
float tilt - 0.3f;
//In case you prefer the rotation in another axis you just need to modify the position of the rigidbody.velocity.x * -tilt
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
Since you didn't add any code I am not sure how you are moving your rocket, so I will post a generic code you will need to adapt depending on your own project:
public class PlayerController : MonoBehaviour
{
public float speed;
//The tild factor
public float tilt;
//The limit within the spaceship can move
public Boundary boundary;
void FixedUpdate ()
{
//You will need to capture the screen touchs of the user for the inputs
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
//Applying the movement to the GameObject
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
//To ensure the GameObject doesnt move outside of the game boundary
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
//Here is where you apply the rotation
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
}
}
As an aside, you are doing a space 2D game you may be interested in checking this tutorial:
https://unity3d.com/learn/tutorials/s/space-shooter-tutorial
One thing you can do is to modify rigidbody.rotation
of your rocket rocket to make it tilt, when it moves, to one direction or to another. For example:
float tilt - 0.3f;
//In case you prefer the rotation in another axis you just need to modify the position of the rigidbody.velocity.x * -tilt
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
Since you didn't add any code I am not sure how you are moving your rocket, so I will post a generic code you will need to adapt depending on your own project:
public class PlayerController : MonoBehaviour
{
public float speed;
//The tild factor
public float tilt;
//The limit within the spaceship can move
public Boundary boundary;
void FixedUpdate ()
{
//You will need to capture the screen touchs of the user for the inputs
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
//Applying the movement to the GameObject
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
//To ensure the GameObject doesnt move outside of the game boundary
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
//Here is where you apply the rotation
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
}
}
As an aside, you are doing a space 2D game you may be interested in checking this tutorial:
https://unity3d.com/learn/tutorials/s/space-shooter-tutorial
answered Nov 21 '18 at 12:29
Ignacio AlorreIgnacio Alorre
3,03042748
3,03042748
I seem to be getting an error saying 'UnityEngine.Component' does not contain a definition for rotation. Any idea what I've done wrong? Thank you
– Mattattack
Nov 21 '18 at 21:18
I have added the code to my question.
– Mattattack
Nov 21 '18 at 21:51
@Mattattack I think the problem is the Quaternion.Euler I posted is expecting a rigidbody, not a rigidbody2D... Try to add a rigidbody (not a 2D) to the gameobject, and then you can access that rigidbody component directly as in my code. That is, remove this: Rigidbody2D rb2d = GetComponent<Rigidbody2D> (); As far as I know the script will access directly the rigidbody component of the GameObject which it's attached to
– Ignacio Alorre
Nov 22 '18 at 7:19
I had added the rigidbody2D trying to get it to work. Without the rigidbody2D it still does not work. When I begin to type rigidbody, the auto complete has a line through it, it is not recognized.
– Mattattack
Nov 22 '18 at 16:52
@Mattattack But you should add the rigidbody as a component of the GameObject from the editor first, then you can access it from code. Can you list what are the components in the rocket GameObject? You can see them from the editor
– Ignacio Alorre
Nov 22 '18 at 20:29
|
show 4 more comments
I seem to be getting an error saying 'UnityEngine.Component' does not contain a definition for rotation. Any idea what I've done wrong? Thank you
– Mattattack
Nov 21 '18 at 21:18
I have added the code to my question.
– Mattattack
Nov 21 '18 at 21:51
@Mattattack I think the problem is the Quaternion.Euler I posted is expecting a rigidbody, not a rigidbody2D... Try to add a rigidbody (not a 2D) to the gameobject, and then you can access that rigidbody component directly as in my code. That is, remove this: Rigidbody2D rb2d = GetComponent<Rigidbody2D> (); As far as I know the script will access directly the rigidbody component of the GameObject which it's attached to
– Ignacio Alorre
Nov 22 '18 at 7:19
I had added the rigidbody2D trying to get it to work. Without the rigidbody2D it still does not work. When I begin to type rigidbody, the auto complete has a line through it, it is not recognized.
– Mattattack
Nov 22 '18 at 16:52
@Mattattack But you should add the rigidbody as a component of the GameObject from the editor first, then you can access it from code. Can you list what are the components in the rocket GameObject? You can see them from the editor
– Ignacio Alorre
Nov 22 '18 at 20:29
I seem to be getting an error saying 'UnityEngine.Component' does not contain a definition for rotation. Any idea what I've done wrong? Thank you
– Mattattack
Nov 21 '18 at 21:18
I seem to be getting an error saying 'UnityEngine.Component' does not contain a definition for rotation. Any idea what I've done wrong? Thank you
– Mattattack
Nov 21 '18 at 21:18
I have added the code to my question.
– Mattattack
Nov 21 '18 at 21:51
I have added the code to my question.
– Mattattack
Nov 21 '18 at 21:51
@Mattattack I think the problem is the Quaternion.Euler I posted is expecting a rigidbody, not a rigidbody2D... Try to add a rigidbody (not a 2D) to the gameobject, and then you can access that rigidbody component directly as in my code. That is, remove this: Rigidbody2D rb2d = GetComponent<Rigidbody2D> (); As far as I know the script will access directly the rigidbody component of the GameObject which it's attached to
– Ignacio Alorre
Nov 22 '18 at 7:19
@Mattattack I think the problem is the Quaternion.Euler I posted is expecting a rigidbody, not a rigidbody2D... Try to add a rigidbody (not a 2D) to the gameobject, and then you can access that rigidbody component directly as in my code. That is, remove this: Rigidbody2D rb2d = GetComponent<Rigidbody2D> (); As far as I know the script will access directly the rigidbody component of the GameObject which it's attached to
– Ignacio Alorre
Nov 22 '18 at 7:19
I had added the rigidbody2D trying to get it to work. Without the rigidbody2D it still does not work. When I begin to type rigidbody, the auto complete has a line through it, it is not recognized.
– Mattattack
Nov 22 '18 at 16:52
I had added the rigidbody2D trying to get it to work. Without the rigidbody2D it still does not work. When I begin to type rigidbody, the auto complete has a line through it, it is not recognized.
– Mattattack
Nov 22 '18 at 16:52
@Mattattack But you should add the rigidbody as a component of the GameObject from the editor first, then you can access it from code. Can you list what are the components in the rocket GameObject? You can see them from the editor
– Ignacio Alorre
Nov 22 '18 at 20:29
@Mattattack But you should add the rigidbody as a component of the GameObject from the editor first, then you can access it from code. Can you list what are the components in the rocket GameObject? You can see them from the editor
– Ignacio Alorre
Nov 22 '18 at 20:29
|
show 4 more comments
What you want is to move your object in global/world space. As it seems the movement of your rocket is currently happening within local space. So when you rotate the rocket it's local coordinates are rotated as well. The world space coordinates are fixed and will never rotate when you change your rocket.
Here is another explanation at that.
You can also have a look at Transform.localPosition and Transform.position and see how your rocket behaves when using one or the other.
I've already tried setting my axis relative to the world and it seemed to have no effect, I may have done something wrong, but it still did not work.
– Mattattack
Nov 21 '18 at 9:41
add a comment |
What you want is to move your object in global/world space. As it seems the movement of your rocket is currently happening within local space. So when you rotate the rocket it's local coordinates are rotated as well. The world space coordinates are fixed and will never rotate when you change your rocket.
Here is another explanation at that.
You can also have a look at Transform.localPosition and Transform.position and see how your rocket behaves when using one or the other.
I've already tried setting my axis relative to the world and it seemed to have no effect, I may have done something wrong, but it still did not work.
– Mattattack
Nov 21 '18 at 9:41
add a comment |
What you want is to move your object in global/world space. As it seems the movement of your rocket is currently happening within local space. So when you rotate the rocket it's local coordinates are rotated as well. The world space coordinates are fixed and will never rotate when you change your rocket.
Here is another explanation at that.
You can also have a look at Transform.localPosition and Transform.position and see how your rocket behaves when using one or the other.
What you want is to move your object in global/world space. As it seems the movement of your rocket is currently happening within local space. So when you rotate the rocket it's local coordinates are rotated as well. The world space coordinates are fixed and will never rotate when you change your rocket.
Here is another explanation at that.
You can also have a look at Transform.localPosition and Transform.position and see how your rocket behaves when using one or the other.
answered Nov 21 '18 at 9:34
yuri206yuri206
715
715
I've already tried setting my axis relative to the world and it seemed to have no effect, I may have done something wrong, but it still did not work.
– Mattattack
Nov 21 '18 at 9:41
add a comment |
I've already tried setting my axis relative to the world and it seemed to have no effect, I may have done something wrong, but it still did not work.
– Mattattack
Nov 21 '18 at 9:41
I've already tried setting my axis relative to the world and it seemed to have no effect, I may have done something wrong, but it still did not work.
– Mattattack
Nov 21 '18 at 9:41
I've already tried setting my axis relative to the world and it seemed to have no effect, I may have done something wrong, but it still did not work.
– Mattattack
Nov 21 '18 at 9:41
add a comment |
You must move your object relative to the world and rotate locally.
So use Transform.position to move your object and Transform.LocalRotation to rotate it.
Or you can put the part that must rotate as a children of the object that translate, and rotate the children.
Can you explain how I can achieve this? I am failing to understand localRotation's properties.
– Mattattack
Nov 21 '18 at 11:33
you use Transform.LocalRotation has you use Transform.Rotation. The difference betwwen those two when you use Rotation it's de rotation of the object relative to the world When you use Local rotation it's relative to his parent.
– Samuel Thauvin Apouchkal
Nov 22 '18 at 14:06
add a comment |
You must move your object relative to the world and rotate locally.
So use Transform.position to move your object and Transform.LocalRotation to rotate it.
Or you can put the part that must rotate as a children of the object that translate, and rotate the children.
Can you explain how I can achieve this? I am failing to understand localRotation's properties.
– Mattattack
Nov 21 '18 at 11:33
you use Transform.LocalRotation has you use Transform.Rotation. The difference betwwen those two when you use Rotation it's de rotation of the object relative to the world When you use Local rotation it's relative to his parent.
– Samuel Thauvin Apouchkal
Nov 22 '18 at 14:06
add a comment |
You must move your object relative to the world and rotate locally.
So use Transform.position to move your object and Transform.LocalRotation to rotate it.
Or you can put the part that must rotate as a children of the object that translate, and rotate the children.
You must move your object relative to the world and rotate locally.
So use Transform.position to move your object and Transform.LocalRotation to rotate it.
Or you can put the part that must rotate as a children of the object that translate, and rotate the children.
answered Nov 21 '18 at 10:14


Samuel Thauvin ApouchkalSamuel Thauvin Apouchkal
13
13
Can you explain how I can achieve this? I am failing to understand localRotation's properties.
– Mattattack
Nov 21 '18 at 11:33
you use Transform.LocalRotation has you use Transform.Rotation. The difference betwwen those two when you use Rotation it's de rotation of the object relative to the world When you use Local rotation it's relative to his parent.
– Samuel Thauvin Apouchkal
Nov 22 '18 at 14:06
add a comment |
Can you explain how I can achieve this? I am failing to understand localRotation's properties.
– Mattattack
Nov 21 '18 at 11:33
you use Transform.LocalRotation has you use Transform.Rotation. The difference betwwen those two when you use Rotation it's de rotation of the object relative to the world When you use Local rotation it's relative to his parent.
– Samuel Thauvin Apouchkal
Nov 22 '18 at 14:06
Can you explain how I can achieve this? I am failing to understand localRotation's properties.
– Mattattack
Nov 21 '18 at 11:33
Can you explain how I can achieve this? I am failing to understand localRotation's properties.
– Mattattack
Nov 21 '18 at 11:33
you use Transform.LocalRotation has you use Transform.Rotation. The difference betwwen those two when you use Rotation it's de rotation of the object relative to the world When you use Local rotation it's relative to his parent.
– Samuel Thauvin Apouchkal
Nov 22 '18 at 14:06
you use Transform.LocalRotation has you use Transform.Rotation. The difference betwwen those two when you use Rotation it's de rotation of the object relative to the world When you use Local rotation it's relative to his parent.
– Samuel Thauvin Apouchkal
Nov 22 '18 at 14:06
add a comment |
You could make the sprite/renderer a child of the GameObject that is your rocket.
Then you can freely rotate the sprite/renderer around without changing the rotation you move the parent GameObject.
This is a hacky solution but it achieves the desired result.
add a comment |
You could make the sprite/renderer a child of the GameObject that is your rocket.
Then you can freely rotate the sprite/renderer around without changing the rotation you move the parent GameObject.
This is a hacky solution but it achieves the desired result.
add a comment |
You could make the sprite/renderer a child of the GameObject that is your rocket.
Then you can freely rotate the sprite/renderer around without changing the rotation you move the parent GameObject.
This is a hacky solution but it achieves the desired result.
You could make the sprite/renderer a child of the GameObject that is your rocket.
Then you can freely rotate the sprite/renderer around without changing the rotation you move the parent GameObject.
This is a hacky solution but it achieves the desired result.
answered Nov 21 '18 at 12:01


Ewout BosEwout Bos
1
1
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408424%2funity-3d-rotating-gameobject-without-rotating-axis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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