Forum rules - please read before posting.

Moving Platform and Setting Parent

Hi.

I am using the first person character from the downloads section.

When i parent it to a moving platform using object->set parent action. It only honours the parent position if I dont move the player. As soon as I move in any direction it loses the parents position and the player moves as if it was not on a platform until i let go of an direction input.

tia

Comments

  • may be worth noting that im using moveable component on the platform

  • i ended up writing my own script to move the platform. I think the moveable component is doing something to mess with the players velocity. Im guessing it wasn't intended for this use case.

  • How are you moving the platform in your script vs the Moveable component? Did the latter have "Move With Rigidbody" checked?

  • in my script nothing too special just using Vector3.Lerp(initialPosition, targetPosition, t);

    i did try with move with rigid body but it didnt work.

    now i have come back to it and retested with moveable and AC actions and now its working as expected. So not sure whats going on. having move with rigid body makes no difference, seems to work.... and i cant seem to replicate the issue now. haha

  • I did recreate this issues. Seems to do things differently after a unity restart.

    So for example.
    Object doesnt not have a moveable. then i add the moveable. - works fine.
    Restart unity - press play and then the issue occurs.
    remove the moveable restart unity and add the moveble back and then its fine again until i restart unity.

  • It may be a Unity issue, in that case. What Unity version/platform are you working with, and are you saving the project before restarting?

    If you can create a .unitypackage file or project .zip that has all the files necessary to demonstrate the issue, PM it to me and I'll take a look.

  • Rather than parenting the Player to the Moveable, attach this script to the Moveable instead:

    using UnityEngine;
    using AC;
    
    public class TransferMoveable : MonoBehaviour
    {
    
        public Moveable moveable;
        private Vector3 offset;
        private Vector3 updatePosition;
    
        void FixedUpdate ()
        {
            offset = KickStarter.player.Transform.position - transform.position;
            updatePosition = KickStarter.player.Transform.position;
        }
    
        void LateUpdate ()
        {
            Vector3 deltaPosition = Vector3.zero;
            if (KickStarter.player.charState != CharState.Idle)
            {
                deltaPosition = KickStarter.player.Transform.position - updatePosition;
            }
    
            if (moveable.IsMoving ())
            {
                KickStarter.player.Transform.position = transform.position + offset + deltaPosition;
            }
        }
    
    }
    
  • Thanks. That does seem to do the trick. had to increase the time update in project settings as the default was a bit jittery.

    appreciate the help

  • To get rid of the jitteriness, try this one instead:

    using UnityEngine;
    using AC;
    
    [DefaultExecutionOrder (-1)]
    public class TransferMoveable : MonoBehaviour
    {
    
        public Moveable moveable;
        private Vector3 offset;
        private Vector3 updatePosition;
    
        void Update ()
        {
            offset = KickStarter.player.Transform.position - transform.position;
            updatePosition = KickStarter.player.Transform.position;
        }
    
        void LateUpdate ()
        {
            Vector3 deltaPosition = Vector3.zero;
            if (KickStarter.player.charState != CharState.Idle)
            {
                deltaPosition = KickStarter.player.Transform.position - updatePosition;
            }
    
            if (moveable.IsMoving ())
            {
                KickStarter.player.Transform.position = transform.position + offset + deltaPosition;
            }
        }
    
    }
    
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.