1
\$\begingroup\$

I've followed 10+ tutorials on setting up basic C# code to allow a player gameObject to stick to a moving platform (even followed the code verbatim) and nothing works. I added some debug print statements to the console to see when the moving platform detects a collision/trigger with the player gameObject and not even the debug print statements are getting triggered.

I'm using the Unity ThirdPersonController asset with the default "Playground" scene loaded.

I created a primitive cube shaped like a platform using the default Box collider. I DID NOT add rigidbody component since this makes the platform wobble when the player bumps into it. Then I added a script component to the platform as follows:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Platform_Stick : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("Hello Collision");
    }

    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("Hello Trigger");
        other.transform.parent = transform;
    }

    private void OnTriggerExit(Collider other)
    {
        Debug.Log("Goodbye Trigger");
        other.transform.parent = null;
    }
}

I used the animator to move the platform left and right. When I jump onto the platform, none of the Debug statements print to console. Does this mean collisions aren't being detected? I also added a second box collider that extends slightly above the platform and checked the box for "Is Trigger".

I'm new to Unity and don't understand why nothing I try is working despite copying tutorials online step by step.

Please help!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Fixed. How the hell would anyone know to do this? Found in some youtube comments:

For the people using a character controller that are having their characters not transform with the platform there's a simple fix!

(Edit -> Project Settings -> Physics (or Physics 2d) -> Auto Sync Transforms

Newer versions of unity don't have Auto Sync Transforms enabled, so check the box and watch your code work!

\$\endgroup\$
1
  • \$\begingroup\$ Good find!54321 \$\endgroup\$
    – Almo
    May 3 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .