0
Answered

Player Stay with a Moving Platform

Shane Peterson 10 months ago in Game Creator updated by Jacob Mann 5 months ago 11

Hello,

I have a trigger that toggles a moving platform's position. When the player is standing on the platform and it's triggered, the player doesn't move with the platform. The platform slides out from under the player and the player falls. Is there a way I can make the play stay on the platform, but also be able to move around?

Unlike the hoverbike tutorial video I'd like to still allow the player to walk around on the platform while it's in motion.

Thanks!

Unity version:
2019.2.13f1
Game Creator version:
1.0.7
GOOD, I'M SATISFIED
Satisfaction mark by Shane Peterson 10 months ago
+1
Answered

Hi Shane;

Unfortunately, we use Unity's default Character Controller, which doesn't inherit the velocity of whatever is the character standing on. There's a way to solve this though, but it's a bit cumbersome.

On the moving platform, add two Triggers and set them as "On Player Collide Enter" and "On Player Collide Exit". The "On Player Collide Enter" will be called each time the player touches the platform. 


You need to use the Action called "Transform" and set the platform as the parent of the Player (set the target as Player and select Parent -> Platform).

For the "On Player Collide Exit" you must do the same, but clearing the parent of the Player.

Hope this helps! We're actively looking for a solution to this problem that works out of the box. For the next Game Creator major iteration we might switch to a Rigidbody based character controller, which solves this problem without further set up.

+2

That worked great!

It's unfortunate that the velocity isn't maintained as my player exits the trigger, but for the use case I'm working on (riding a hot air balloon and simple elevators) it's fine.

Thank you.

I tried this exactly as described but it does not work anymore? I tried both with moving an character as platform, and as an moving mesh only. BUt somehow the platform keep ssliding away underneath the player.

Yes, changing the parent doesn't work for the platform. Marti, fix it, please.

+1

To make it work, I use scripts from the Gamekit3D addon. ((I'm not a programmer - I can't write this myself)). The first one - "Trigger Command" just lies in the Scripts folder. The second - "Platform" - hang on the moving platform. We add the "Player" layer for this script for the character. And the third "Trans_Parent" - also hang on the platform.

using UnityEngine;

namespace GameCommands

{

public class TriggerCommand : SendGameCommand

{

protected override void Reset()

{

if (LayerMask.LayerToName(gameObject.layer) == "Default")

gameObject.layer = LayerMask.NameToLayer("Environment");

var c = GetComponent<Collider>();

if (c != null)

c.isTrigger = true;

}

}

}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

namespace GameCommands

{

public class Platform : MonoBehaviour

{

public LayerMask layers;

protected CharacterController m_CharacterController;

const float k_SqrMaxCharacterMovement = 1f;

void OnTriggerStay(Collider other)

{

if (0 != (layers.value & 1 << other.gameObject.layer))

{

CharacterController character = other.GetComponent<CharacterController>();

if (character != null)

m_CharacterController = character;

}

}

void OnTriggerExit(Collider other)

{

if (0 != (layers.value & 1 << other.gameObject.layer))

{

if (m_CharacterController != null && other.gameObject == m_CharacterController.gameObject)

m_CharacterController = null;

}

}

public void MoveCharacterController(Vector3 deltaPosition)

{

if (m_CharacterController != null && deltaPosition.sqrMagnitude < k_SqrMaxCharacterMovement)

{

m_CharacterController.Move(deltaPosition);

}

}

}

}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Trans_Parent : MonoBehaviour

{

void OnTriggerEnter(Collider other)

{

if (other.tag == "Player")

{

other.transform.parent = transform;

}

}

void OnTriggerExit(Collider other)

{

if (other.tag == "Player")

{

other.transform.parent = null;

}

}

}

Can someone who understands scripting write an Action for GC based on this?

There are some tutorial videos on some basic scripts for this. but would be an good thing to have these options in Game Creator itself already. I am surprised to see Gamecreator seems to miss many basic features. I hope the builders of Game Creator have focus and vision how and why specific tools are more meaningful to integrate first in future updates. But so far I have all trust in that. 

So I got this to work in my tests. here is my action set up:

I've noticed it's important the scale of the platform be 1, 1, 1  Other wise the player model distorts 

Edit: Note I'm using this as an elevator platform, you can set it up to have the player freely move, this is just my use case.
Elevator Test.mp4

Edit2: 
Going to also point out you'll want a secondary collision with "is trigger" flagged.

what happens when the platform moves horizontal? That is my problem, rhe player will be able to move, but still tbe platform moves away under the player his feet.

Here's a video of the horizontal platform I made
https://imgur.com/a/Av45ezY

Here's my set up 

Thanks! I had thesame setup. But I made the platform huge because I want an big bus to move in freely during the ride. That causes glitching anyway?

You said the scale is important, but It is not what I need, an small platform. Mayby I can connect multiple platforms into one large one, will try one last time.


What I did was parent the box to an empty, then you can have any size platform you want