bmyagkov Posted July 18 Posted July 18 Hello! 9 hours ago, Sevdat said: How can I change the gravity by code? The following method might help you address this task: https://developer.unigine.com/en/docs/2.18.1/api/library/physics/class.physics?rlang=cs#Gravity Physics.Gravity = new vec3(10,2,-1); Thanks!
Sevdat Posted July 18 Author Posted July 18 47 minutes ago, bmyagkov said: Hello! The following method might help you address this task: https://developer.unigine.com/en/docs/2.18.1/api/library/physics/class.physics?rlang=cs#Gravity Physics.Gravity = new vec3(10,2,-1); Thanks! Good morning bmyagkov, this works, but it changes the gravity of the entire world. How can I change the gravity of individual objects? For example, object 1 has gravity: Physics.Gravity = new vec3(0,0,-3); object 2 has gravity: Physics.Gravity = new vec3(0,-10,-25);
bmyagkov Posted July 18 Posted July 18 1 hour ago, Sevdat said: this works, but it changes the gravity of the entire world. How can I change the gravity of individual objects? For example, There is no way to set a gravity value per object but you can disable it using body.Gravity = false and apply forces in your own way specifically through this method. Thanks! 1
Sevdat Posted July 18 Author Posted July 18 (edited) 1 hour ago, bmyagkov said: There is no way to set a gravity value per object but you can disable it using body.Gravity = false and apply forces in your own way specifically through this method. Thanks! Good day bmyagkov, The addforce method works, but I have a question about disabling gravity: ObjectMeshDynamic clone; public ObjectMeshDynamic createSphere(float radius,vec3 position,int i){ ObjectMeshDynamic sphere = Primitives.CreateSphere(radius, 9, 32); sphere.TriggerInteractionEnabled = true; sphere.SetIntersection(true, 0); sphere.SetIntersectionMask(1, 0); sphere.SetCollision(true,0); sphere.SetCollisionMask(1, 0); sphere.WorldPosition = position; sphere.Name = $"{i}"; BodyRigid bodySphere = new BodyRigid(sphere); new ShapeSphere(bodySphere, 2); bodySphere.ShapeBased = false; bodySphere.Mass = 1f; return sphere; } private void Init(){ Visualizer.Enabled = true; Unigine.Console.Onscreen = true; Physics.ShowShapes = Physics.SHOW_TYPE.SOLID; clone = createSphere(1f,new vec3(1,1,60),1); clone.BodyRigid.Gravity = false; } private void UpdatePhysics(){ clone.BodyRigid.AddForce(new vec3(0,0,-9.81f)); } I noticed that there is 2 ways of disabling gravity: 1) clone.BodyRigid.Gravity = false; 2) clone.Body.Gravity = false; Which method would be the correct approach of disabling gravity? Edited July 18 by Sevdat
cash-metall Posted July 18 Posted July 18 32 minutes ago, Sevdat said: Which method would be the correct approach of disabling gravity? Any of them. this is the same method. Rigidbody just inherits it from Body class 2
Recommended Posts