JeremyG Posted July 18, 2021 Share Posted July 18, 2021 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:" 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
karpych11 Posted July 19, 2021 Share Posted July 19, 2021 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); 3 1 Link to comment
JeremyG Posted July 20, 2021 Author Share Posted July 20, 2021 (edited) Thank you for the answer and explanation! That worked like a charm! Edited July 20, 2021 by JeremyG 1 Link to comment
TanukiDigital Posted October 26, 2023 Share Posted October 26, 2023 @karpych11 This answer saved my butt! Thanks! :D Link to comment
Recommended Posts