Forum rules - please read before posting.

Attaching player to moving object

edited January 2021 in Technical Q&A

AC Ver: 1.72.2
Unity Ver: 2019.4.8f1

Hello,

I'm trying to attach the player to an object that moves along a spline, however I'm getting some weird position results. I totally understand this might not ultimately be an AC issue but I want to make sure at least it all seems correct on the AC side of things.

The spline object is just some simple cubes with an empty 'seat' object for where the player should be positioned later on:

This uses an asset called Bezier Solutions in order to move which results in this:

This GIF also shows the problem; the player / player camera is moving all over the place after being parented and isn't sticking, as I would expect, with the parented "seat".

Here's how I go about attaching the player to the object:

First, I swap the player out for a special version. This special player has all collision and gravity disabled and also has a motion control of 'manual'. Then, I parent them to an empty gameobject called "seat". Finally, I initiate the movement.

Does anybody have any ideas where I should start?

Comments

  • edited January 2021

    I've done a little more digging and we can see the problem here; the player capsule / object is being stretched and moved all over the place:

    The player object should be parented and fixed to the to the point where the gizmos are.

  • edited January 2021

    Solved it, I think. If I disable player movement in Engine: Manage Systems it's fine:

    Doing that however has removed mouse look which I want to keep active (so the player can turn the camera and look around). Any ideas how I can retain that?

  • edited January 2021

    There should be a couple of ways you could go about it:

    1) Rely on a custom camera type (attach a custom camera script to a SimpleCamera and switch to it when the sequence begins), so that it's movement is independent of AC.
    2) Rather than parenting the Player to the seat, use a script that simply copies its position every frame, i.e.:

    void Update ()
    {
        transform.position = seatTransform.position;
        transform.forward = seatTransform.forward;
    }
    
  • Thanks @ChrisIceBox, I've tried the 2nd solution and getting positive results so I'll roll with that. I'm interested though why simple parenting doesn't work in this case. Does it make sense why the player object would stretch and move around when parented?

  • Not entirely sure, to be honest. It shouldn't be AC's doing.

    Is it a Capsule Collider, or a Character Controller? It may be built in behaviour - the object itself is remaining in place, the capsule itself is being offset.

  • edited January 2021

    The capsule you see is an inactive capsule component. Otherwise it's just a standard AC player with a Player component. You can see the position numbers changing all over the place so the object itself isn't staying in place with parenting.

  • Considering the player is now a child of the object, perhaps it's all to do with inherited rotations and transforms screwing things up.

  • It was a inherited scale problem. It was due to the fact the object I was parenting it to wasn't at scale 1,1,1. Oooops.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.