christian.neerup Posted June 7, 2020 Share Posted June 7, 2020 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) Now this is actually what the code does in-game. (alternatively view the mp4) 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 Posted June 9, 2020 Share Posted June 9, 2020 Hi Christian, Please take a look at the code my colleague wrote for such camera controls. See attached files. Regardstest.worldStrategicCameraController.cs 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
christian.neerup Posted June 9, 2020 Author Share Posted June 9, 2020 This works great, I'll try to see if I can wrap my head around this. Thank you. Link to comment
Recommended Posts