Jump to content

Rotating a node in World Coordinates?


photo

Recommended Posts

Hi all!

I'm new to Unigine, have some experience with Unity/Unreal/Godot, which is why this question is potentially embarrassing!

In following along the C# Components video, I wrote my own rotating object script just to get a feel for the scripting in Unigine. However, I decided I want to make a spotlight like object with a light that is angled and rotate it in World space. I have it angled like this:
spotlight_example.thumb.png.9ae7e31099899fc34946cd33b544e0fd.png"

I tried using both node.Rotate and node.WorldRotate, but no matter what, the result is the same, and the spotlight only rotates around the local z axis, rather than the World z axis. 

Is there something obvious I'm missing? This is my code:
 

using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;

[Component(PropertyGuid = "28521a6c93ad52dbe2a26a7edb6a8fc5e05dbe60")]
public class SpinnySpinny : Component
{
	public float rotation_speed = 100.0f;

	private void Init()
	{
		// write here code to be called on component initialization
		Log.Message("Name of node = " + node.Name + "\n");
	
	}
	
	private void Update()
	{
		// Rotate the node
		node.WorldRotate(0, 0, rotation_speed * Game.IFps);
	}
}

Thank you any responses!

Link to comment

Hello,

The node.rotate and node.worldRotate methods perform the following transformations:

node.SetRotation(node.GetRotation() * new quat(0.0f, 0.0f, rotation_speed * Game.IFps));

and

node.SetWorldRotation(node.GetWorldRotation() * new quat(0.0f, 0.0f, rotation_speed * Game.IFps));

In these two cases, we rotate the object around its Z axis, and the only difference is whether the transformation of the parent node is taken into account or not.

In your case, you need to rotate the node around its non-basis axis in world space. To do this, you can use the following:

quat rot = node.GetWorldRotation();
rot = new quat(0.0f, 0.0f, rotation_speed * Game.IFps) * rot;
node.SetWorldRotation(rot);

 

  • Like 1
  • Thanks 1
Link to comment
×
×
  • Create New...