Godot: RigidBody 3D Collision problem and flickering when using look_at Function

Created on 18 Jan 2018  路  15Comments  路  Source: godotengine/godot

Godot version:
Godot 3 win x64 : b10172610
Build date: 2018-01-17 13:04:01
Downloaded from : http://godot3builds.digitecnology.com/
Also Godot 3 Beta 2 win x64

Issue description:
using Bullet
when using look_at function while moving .. the RigidBody collision will not work well and sometimes it start flickering

Minimal reproduction project:
CollisionBug.zip

bug physics

Most helpful comment

Yes, the Spatial and the state transform are different (and should stay like that, IMO), other engines hide the operations done to the body component.

Maybe a warning should be shown when changing a PhysicsBody's node transform, and easier access to the body state too because is needed on KinematicBody for rotation and teleport (right now is accessed via PhysicsServer, but the node should have a reference to the state).

All 15 comments

i found a solution to avoid that
you can make the rigid body move and Collide while looking at object by :

state.set_transform(state.get_transform().looking_at(ObjectLocation, Vector3(0, 1, 0)));
self.set_rotation(Vector3(0,self.get_rotation().y,0));

and for the Collision Create : Trimesh collision sibling
and the rigid body will collide better than before

This needs to be solved before godotphysics being removed ( @akien-mga ?)

If the problem is Bullet-specific, sure. CC @AndreaCatania

I didn't check the project yet, but if you are trying to move/rotate a rigidbody using set_transform set_rotation each tick you are doing wrong. Instead you should use forces, impulse or velocity to move a rigid body.

Set_transform should be used only in case you need a "teleport"

the problem can be reproduced in this code made by @aarroz https://github.com/aarroz/simplefps

Exactly what I mean: https://github.com/aarroz/simplefps/blob/master/assets/simple_fpsplayer/Player.gd#L31-L50

The rigid body is not meant to be moved by updating its position... You have to control it by using forces, impulse, or velocity.

In godot physics you don't register the flickering but it's not the correct way to handle it either

hmm, so it is a code problem, i might take a look and send a pull request

Check Godot demos

@AndreaCatania i'm not moving the rigidbody using set_transform and set_rotation
i'm using state.set_linear_velocity(MoveDirection)

you should check the example and see it

The function

look_at(ObjectToLookAt.global_transform.origin,Vector3(0,1,0))

Change the character rotation directly like if you use set_rotation. Here you have two way to implement it

  1. Use kinematic body and look_at will work
  2. Implement your custom look_at function that internally will change character rotation using forces / impulse or angular velocity

It is quite possible that this issue is the wrong place, but would it be technically possible that if a function is used that does not work correctly with a RigidBody/KinematicBody or is not to be used, that it does the job internally correctly?

I have in mind that when for example changing the position, the node type is checked first and then the correct internal function corresponding to the node is used. (set_transform)

During the last months I see so many issues that all have to fight with the same problems. The solution was mostly, no you are not allowed to use this offered function but have to create a workaround.

Change position of kinematic body is always correct, the problem occurs when you change the position of rigid body.

RigidBody position can be updated using set_global_transform and other similar function without any care about.
The real problem is when you change the position of it frame by frame and you expect that physics engine is able to simulate physics behaviour correctly.

A rigid body must always be leave free to move in the world to have a correct physics bahaviour, and you have to interact with it using forces or by chancing velocity.

So I don't like at all the idea to show a warning when you move a rigidbody since this problem occurs due to wrong understanding of rigidbody node and not the bad implementation of set_global_transform function.

Probably something about this should be written in the DOCs

i can't use Kinematicbody in this project , i must use Rigidbody , in UE4 this work perfect , but with Godot for some reason you must use :

state.set_transform(state.get_transform().looking_at(ObjectLocation, Vector3(0, 1, 0)));

instead of

look_at(ObjectLocation,Vector3(0,1,0))

in Rigidbody to work well without any problem

Yes, the Spatial and the state transform are different (and should stay like that, IMO), other engines hide the operations done to the body component.

Maybe a warning should be shown when changing a PhysicsBody's node transform, and easier access to the body state too because is needed on KinematicBody for rotation and teleport (right now is accessed via PhysicsServer, but the node should have a reference to the state).

I written a doc about rigid body: https://github.com/godotengine/godot-docs/pull/1277

Was this page helpful?
0 / 5 - 0 ratings