Jump to content

[SOLVED] Rotating camera left/right - rotation becomes unstable


photo

Recommended Posts

Hello everyone,

I am trying to make a camera that can rotate left and right in world space, by holding the middle mouse button and dragging. This is the first thing I've been trying to make in Unigine.

It works for a while but it has an issue, where the rotation slowly causes the camera to look directly into the horizon once it gets there the rotation also starts to roll the camera until a 90 degree roll is realized.

The camera starts at coordinates 0,0,0, rotation 50,0,0.

This is the code that is supposed to do the rotation. (That is inside of the UpdatePhysics-method on a component attached to the camera's parent).

if (EnableMouseRotation && Input.IsMouseButtonPressed(Input.MOUSE_BUTTON.MIDDLE))
{
	vec3 rotation = vec3.UP * Input.MouseDelta.x * node.GetRotation();
	node.Rotate(rotation);
}

I want the rotation to be like illustrated in this gif, and it does that for a while, it seems. (alternatively view mp4 instead)

spacer.png

Now this is actually what the code does in-game. (alternatively view the mp4)

spacer.png

I am not sure if this is a bug or just me being very bad at math, but I suspect I just don't know what I am doing here. I've been looking at it for several hours trying to do it in different ways, then last night I decided to see if I could do it in Unity instead, and that works perfectly fine using this code.

if (Input.GetMouseButton((int)MouseButton.MiddleMouse))
{
	if (lastMousePosition.HasValue && lastMousePosition != Input.mousePosition)
	{
		Vector3 delta = lastMousePosition.Value - Input.mousePosition;
		transform.Rotate(new Vector3(0, delta.x, 0), Space.World);
	}

	lastMousePosition = Input.mousePosition;
}

So that is essentially what I want to achieve in Unigine, I note there that it is an actual world space rotation, for some reason whenever I try to use node.WorldRotate() it just doesn't do what I want at all.

If someone could tell me what I need to do differently I would really appreciate that. I've attached the entire component code and the world file.

Thank you

test.world StrategicCameraController.cs

Link to comment
  • morbid changed the title to [SOLVED] Rotating camera left/right - rotation becomes unstable
×
×
  • Create New...