Last active
February 17, 2022 15:49
-
-
Save nothke/ee83085ba2510246cccb6bed6c6d1ccf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Add this script to the parent of colliders you wish to sync to the root rigidbody | |
using KinematicCharacterController; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class BuildKCCPlatform : MonoBehaviour | |
{ | |
public Transform source; | |
public bool destroySource = false; | |
void Start() | |
{ | |
if (source == null) | |
source = GetComponentInParent<Transform>(); | |
GameObject go = Instantiate(gameObject); | |
go.transform.localScale = transform.lossyScale; | |
Destroy(go.GetComponent<BuildKCCMover>()); | |
var children = go.GetComponentsInChildren<Transform>(); // alloc | |
for (int i = 0; i < children.Length; i++) | |
{ | |
Transform child = children[i]; | |
if (!child) | |
continue; | |
child.gameObject.layer = 9; // HARDCODED LAYER!! | |
// if one of the children has a mover, destroy it | |
if (child.gameObject != go && child.GetComponent<BuildKCCMover>()) | |
Destroy(child.gameObject); | |
} | |
var moverTets = go.AddComponent<KCCGhostPlatform>(); | |
moverTets.sourceObject = source; | |
go.AddComponent<PhysicsMover>(); | |
if (destroySource) | |
Destroy(gameObject); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using KinematicCharacterController; | |
public class KCCGhostPlatform : MonoBehaviour, IMoverController | |
{ | |
public Transform sourceObject; | |
PhysicsMover _mover; | |
PhysicsMover mover { get { if (!_mover) _mover = GetComponent<PhysicsMover>(); return _mover; } } | |
private void Start() | |
{ | |
mover.MoverController = this; | |
} | |
public void UpdateMovement(out Vector3 goalPosition, out Quaternion goalRotation, float deltaTime) | |
{ | |
goalRotation = sourceObject.rotation; | |
goalPosition = sourceObject.position; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment