I’ve been trying to create a first person player controller which can handle physics object.
The Player has a RigidBody, as does the object I want it to pick up and move.
I’ve been trying several different ways to have both physics enabled in the picked object while avoiding weird/glitchy behaviour in the player.
The closest I’ve gotten was to use a FixedJoint between the item and the player. After a bit of trial and error it works almost flawlessly: It follows the player movement and rotation, it reacts to other colliders (like pushing against a wall, getting caught on world geometry etc.)
The only issue I have is that the object’s movement appear jittery on the Player camera. It must have something to do on how I handle the player camera, because when seen through another fixed camera I had placed in the Scene, the object moves smoothly:
I tried using Physics to move the object towards the grabber but it’s always really janky and has a delay in following the camera. I tried setting the object as a child to the player but it only works if it is set as Kinematic, which makes it not interact with colliders.
Currently, my setup works like this:
-
in Update
- I update the CameraDirection object (an empty object which only contains coordinates) rotation with mouse movements and position based on Player Transform.
Updating CameraDirection in FixedUpdate results in everything looking Jittery, as does using the RigidBody instead of Transform. Even with Interpolate on. - I update the Grabber using CameraDirection position and rotation.
- Move Camera using CameraDirection position and rotation. Also tried doing in LateUpdate, no changes I could notice.
- I update the CameraDirection object (an empty object which only contains coordinates) rotation with mouse movements and position based on Player Transform.
-
In FixedUpdate:
- Moving the player using AddForce VelocityChange. I don’t rotate the RigidBody, only the renderer to avoid issues.
- Updating the ConnectedAnchor position of the held object’s joint using the Grabber Transform. The held object is not a child of the Player (this created conflicts between the two Rigidbodies) and is set to Interpolate.
Here is the Hierarchy:
There must be something conflicting between the object movements, the grabber movements, or the camera movements.
If I disable rotation of the player camera the object moves smoothly, as it does if I make it follow the grabber as a Kinematic object (which I will do as last resort, but this way does not interact with walls or other colliders).
I would really appreciate any idea on how to improve the situation.
As of now my only idea is to set the object as Kinematic, make it a Child of the Player character then increasing the Player collider to avoid the held object clipping through walls and such, but this would make the interaction more dull in my opinion.