Sevdat Posted July 7, 2023 Share Posted July 7, 2023 (edited) How can I fix the gravity? var dir = camera.GetWorldDirection(); var lol = Physics.Gravity; dir.z = 0; if (dir.Length2 != 0) { dir.Normalize(); camera.Target.SetWorldDirection(dir, vec3.UP, MathLib.AXIS.Y); } I found this form and I'm trying to use mat4, but it's not working. Edited July 7, 2023 by Sevdat Link to comment
silent Posted July 7, 2023 Share Posted July 7, 2023 Sevdat I'm afraid, it's not completely clear - what is not working? Can you show us the code and compiler errors if any? Thanks! 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
Sevdat Posted July 7, 2023 Author Share Posted July 7, 2023 (edited) Good day silent, The compiler doesn't give errors. camera.Target.SetWorldDirection(dir, vec3.UP, MathLib.AXIS.Y); When SetWordlDirection is added to update(), for some reason although the gravity remaining to be in -9.81, the object falls slowly. I read that setPreserveTransform and addAngularImpulse is used to preserve the vectors, but I don't understand how to implement them. Also I have noticed that in the website, when editing, menu is invisible. I attached a photo below to demonstrate it. This is the full code It's the same one cash metall suggested to me earlier using System; using System.Collections; using System.Collections.Generic; using Unigine; [Component(PropertyGuid = "a95c371ff61b19f210c7b0a9e77741f4f29884c3")] public class cameraPersecutor : Component { private PlayerPersecutor camera; // public ObjectMeshStatic player; private void Init() { camera = node as PlayerPersecutor; // write here code to be called on component initialization // Unigine.Console.Run("console_onscreen 1"); } float distance = 5.0f; private void Update() { // write here code to be called before updating each render frame camera.Distance = 5.0f; vec3 camera_rot = camera.GetWorldDirection(); // camera.Target.SetWorldDirection(vec3.UP, camera_rot, MathLib.AXIS.Z); // force update camera camera.Controlled = true; camera.UpdateControls(Game.IFps); camera.FlushTransform(); camera.Controlled = false; var dir = camera.GetWorldDirection(); var lol = Physics.Gravity; dir.z = 0; if (dir.Length2 != 0) { dir.Normalize(); camera.Target.SetWorldDirection(dir, vec3.UP, MathLib.AXIS.Y); } // Log.Message("phi:" + old + "\n"); Log.Message("x:" + lol + "\n"); } } Edited July 7, 2023 by Sevdat Link to comment
cash-metall Posted July 10, 2023 Share Posted July 10, 2023 Hello! when you change a node's transformation, physical forces are reset. - it works like a teleportation. you should use only physical methods addForce/addImpulse/addTorque if it is not possible to calculate the force, and you want to change Transform directly - you can use the methods setPreserveTransform / setVelocityTransform vec3 pos = camera.Target.WorldPosition; mat4 t = MathLib.SetTo(pos, pos + dir, vec3.UP, MathLib.AXIS.Y); camera.Target.ObjectBody.SetPreserveTransform(t); but you should call it in PhysicsUpdate() methods 1 Link to comment
Recommended Posts