Search Unity

Help Wanted What is the best approach to implementing passengers?

Discussion in 'DOTS Physics' started by TheOtherMonarch, Jun 17, 2021.

  1. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    280
    What is the best way to implement passengers? I can think of a few way to deal with character controllers entering vehicles. The passengers will be seated and have restricted animations.

    1: Parent and remove components from the character controller (Physics Body and Physics Shape).
    2: Use a fixed joint I have not really looked into joints yet.
    3: Do something like PlatformMotionSystem this seems over kill.
    4: Wait until disable components becomes a thing.

    Right now with gameObjects I do something like option 1#.
     
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    480
    #1 sounds like the option. Add a Parent and a PhysicsExclude component. Then remove both when they need to disembark.
     
    TheOtherMonarch likes this.
  3. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    280
    I did not know about PhysicsExclude thanks. Does this exclude only the tagged entity or also children? I have the rigidbody collider and also children hit box colliders. I would like the hit boxes to still function.
     
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,310
    What's simplest depends on the controller. Like with kinematic controllers I've found it easier to use a passenger component that stores the passenger local to to vehicle. Then it's as simple as a boarding/unboarding that adds/removes the passenger component and stores the local translation/rotation and a job with a signature like below which updates the world position/rotation. The controller should just set velocity to 0. No adding/removing physics components or transform system parenting which is more complex, especially given you likely will have a passenger component of some type anyways.

    .ForEach(Passenger p, Translation t, Rotation r)
     
    steveeHavok likes this.
unityunity