Gonzi Posted May 2, 2020 Share Posted May 2, 2020 Hi, I am trying to have a PlayerDummy and move him with directional vectors. You point out in the documentation, that I need to recalculate something, otherwise the movement won't work correctly. I've spent some time on that, but I am unable to do it 'correctly' (so that adding vec3.forward rotated by player rotation will be forward and not up). My code works right now as I would expect, but I have to use the wrong vectors for it: if (Input.IsKeyPressed(KEY.W)) { player.Position = player.Position + player.GetRotation() * vec3.DOWN * Game.IFps * speed; // should be vec3.FORWARD } if (Input.IsKeyPressed(KEY.S)) { player.Position = player.Position + player.GetRotation() * vec3.UP * Game.IFps * speed; // should be vec3.UP } if (Input.IsKeyPressed(KEY.A)) { player.Position = player.Position + player.GetRotation() * vec3.LEFT * Game.IFps * speed; } if (Input.IsKeyPressed(KEY.D)) { player.Position = player.Position + player.GetRotation() * vec3.RIGHT * Game.IFps * speed; } if (Input.IsKeyPressed(KEY.Q)) { player.Rotate(0, 0, Game.IFps * rotspeed); } if (Input.IsKeyPressed(KEY.E)) { player.Rotate(0, 0, -Game.IFps * rotspeed); } if (Input.IsMouseButtonPressed(MOUSE_BUTTON.RIGHT)) { player.Rotate(Game.IFps * Input.MouseDelta.y * rotspeed, 0, 0); player.Rotate(0, Game.IFps * Input.MouseDelta.x * rotspeed, 0); } I've tried several things like this, but it didn't change anything: player.SetDirection(vec3.FORWARD, vec3.UP); // nothing player.ViewDirection = vec3.FORWARD; // no joy If I drag the player to the scene, it's automatically looking down, so it works correctly in that way(forward would be forward in top down shooter for example). So: Is that expected behavior and is my use of other vectors correct, or should I do something differently? Is your default camera/player implementation available somewhere? Thank you Link to comment
karpych11 Posted May 5, 2020 Share Posted May 5, 2020 Hello, For nodes and cameras the directional vectors are different. For the camera the forward direction is the -Z axis and the upward is the +Y axis. You can read more at the link: https://developer.unigine.com/en/docs/2.11/code/fundamentals/matrices/ To move the camera, I would recommend using the Translate method. For example: vec2 axes = vec2.ZERO; if (Input.IsKeyPressed(Input.KEY.W)) axes.y += 1.0f; if (Input.IsKeyPressed(Input.KEY.S)) axes.y -= 1.0f; if (Input.IsKeyPressed(Input.KEY.D)) axes.x += 1.0f; if (Input.IsKeyPressed(Input.KEY.A)) axes.x -= 1.0f; player.Translate(new vec3(axes.x, 0.0f, -axes.y) * Game.IFps * speed); You can find camera implementations in the folder with the installed SDK source\csharp\samples\Api\Nodes\CustomPlayers. You can also find camera examples in C# Component Samples. 1 Link to comment
Gonzi Posted May 5, 2020 Author Share Posted May 5, 2020 Thank you, I've somehow managed to miss that graph on matrices page and I've just found out that I was not looking deep enough into the examples :-D I thought that they use some "default controller" when none is provided, but it was just a few folders down *sigh*. Link to comment
Recommended Posts