fubes
New vMember
Posts: 3
|
Post by fubes on Feb 22, 2024 22:59:51 GMT
Hi, I'm using the Third Person Locomotion Template and I'm having issues with moving/rotating platforms. It's simple to reproduce: the character stands on a Rigidbody platform that is being rotated by torque. But the platform is rotating under the character without dragging the character along. Other rigidbody-objects placed on the platform will be moved with the platform. I think it might have to do with the capsule collider of the character not touching the ground, hence no friction is applied between the platform and the character. There seems to be some logic which shrinks the capsule in context of the stepHeight. As you can see in the screenshot, the capsule begins at the knees and not at the feet of the character. Is there an easy way to get this to work? Thank You!
|
|
|
Post by Invector on Feb 23, 2024 13:54:58 GMT
Take a look at the Basic Locomotion demo scene, there is a example of moving plataform there
|
|
fubes
New vMember
Posts: 3
|
Post by fubes on Feb 23, 2024 19:21:30 GMT
Thanks for the reply, but this would only work for a non-rigidbody platform. In my case the character should be able to stand and walk on a platform (a boat) which is affected by physics itself. The vPlatform does the trick by parenting the character to the platform but this can't be done when both objects are rigidbodies.
In the demo version of the Basic Locomotion template i got it to work with the friction between the players capsule and the rigidbody-platform but now in the full version the player capsule is displaced and does not touch the ground, as can be seen in the screenshot.
|
|
fubes
New vMember
Posts: 3
|
Post by fubes on Mar 2, 2024 10:21:17 GMT
I found a pretty simple solution that avoids reparenting a Rigidbody to another Rigidbody: The Character is being parented to a special set of colliders on their own physics layer, that mimic the original moving platform colliders orientation. This way the character is moved along with the moving platform and can also move freely on the platform.
- Copy all relevant Colliders of the "Moving Platform" (in my case the deck of the ship) - Move them to their own physics layer (e.g. "Moving Platform") - Exclude this layer from the moving platforms Rigidbody - Make sure that the characters Rigidbody includes this new layer - Group the colliders at the same hierarchy level as the Rigidbody of your moving platform, so that they are not a child of the Rigidbody - Add a script to the group that copies the moving platform Rigidbody position and rotation to these Colliders on each FixedUpdate (see bottom: SyncPositionWithRigidbody) - Add a trigger collider below the feet of the character - Add a script to the trigger collider to automatically reparent the player controller to the MovingPlatform (see MovingPlatformAutoParent)
using UnityEngine;
public class SyncPositionWithRigidbody : MonoBehaviour { public Rigidbody rb;
private void FixedUpdate() { transform.SetPositionAndRotation( rb.position, rb.rotation ); } }
using UnityEngine; using Invector.vCharacterController;
public class MovingPlatformAutoParent : MonoBehaviour { [Tooltip( "Used to determine wether character is grounded." )] public vThirdPersonController thirdPersonController;
protected Transform currentParent;
private void FixedUpdate() { if( currentParent != null && thirdPersonController.isGrounded ) { thirdPersonController.transform.parent = currentParent; } else { thirdPersonController.transform.parent = null; } }
private void OnTriggerStay( Collider other ) { if( currentParent == null && other.gameObject.layer.Equals( LayerMask.NameToLayer( "MovingPlatform" ) ) ) { currentParent = other.transform; } }
private void OnTriggerExit( Collider other ) { if( other.transform.Equals( currentParent ) ) { currentParent = null; } } }
|
|