Jump to content

Basic rotation


Recommended Posts

Very simple.

I have a mesh and I would like to rotate it by setting the current rotation.x to +=0.05.
I am actually looking to rotate an object in about 10 degrees on x axis, from initial position. 

I tried mesh._rotation.x = 0.05 and the result is not what I want. 
This rotates the mesh 0.05 on EVERY frame. This means that I get an additional rotation per frame render.

Instead I want the rotation to be SET to 0.05 (not incremented).
I need to set the rotation in absolute terms, not relative.

How can this simple thing be done?
Thanks so much in advance!

P.S: I even tried:

mesh.rotate(BABYLON.Axis.X, 0.1, BABYLON.Space.WORLD);

..but again this rotates 0.1 on EVERY frame and rotation is accumulated.
I want to set the rotation to the absolute number of 0.1 (not an incremental relative number)

Link to comment
Share on other sites

Head over to https://playground.babylonjs.com/ and at the top right, change from "Basic Scene" to "Rotation and Scaling". There, you'll see the code required to do rotations the way you want.

The rotations are not based on 360 degrees. 360 degrees is actually 2xPi (or about 6.28). To rotate by n degrees, you'd want to rotate by a value of (2 * Math.PI) / 360 * n.

Link to comment
Share on other sites

Thanks @Magilla and @JohnK however this does not solve my problem.

The two functions rotate the object every time.
If I have a loop:

  mesh.rotation.x = 0.05;
..will rotate the mesh on every loop frame.
I don't want that. I want to SET the rotation INSIDE the loop (not at the creation of the scene) to specific rotation coordinates.

How can I do that?


Link to comment
Share on other sites

I am missing something when you SET any rotation INSIDE a loop the rotation will be called for each frame of the loop by definition of a loop.  Please give a simple playground with comments to show what you want to happen and where.

Link to comment
Share on other sites

20 hours ago, Rodrix3 said:

I have a mesh and I would like to rotate it by setting the current rotation.x to +=0.05.

Are you using rotation.x = 0.05 or rotation.x += 0.05 in your code? rotation.x += 0.05 is the same as saying rotation.x = rotation.x + 0.05 which will DEFINITELY cause your mesh to spin every frame, because it will change (add 0.05 to) the value of rotation.x every time the loop goes through. To set the value so it doesn't change, use rotation.x = 0.05.

Link to comment
Share on other sites

Until you show us some code, we have two options:

  1. Show you it working correctly (see my first post)
  2. Make wild guesses (see the rest of the thread)

The behaviour you describe does not make sense in my experience of the system, so unless someone has seen it and solved it previously, I don't know that there's a lot more we can do.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...