Jump to content

Slow Gravity - object falls slowly when rotation is added


photo

Recommended Posts

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 by Sevdat
Link to comment

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.

image.thumb.png.bd6769ed7b35cdefe118efcc4495ef9f.png

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 by Sevdat
Link to comment

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

  • Like 1
Link to comment
×
×
  • Create New...