So, I have an array of four square platforms that rotate in a circle around a center point. They each pass by the square that the player spawns on. When the player jumps onto one of the platforms to ride it around the loop, the Character Controller becomes a child of the platform, but that means that when the player jumps onto the platform, their rotation gets switched to the platform’s current rotation. I’d like the player to be able to move freely while the platform carries them around, but I can’t figure out how to prevent the rotation issue and move the player with the platform without essentially gluing their feet to the it. Are there any ways to allow a player to ride the platforms while still being completely in control of their rotation? The code I’m currently using is below. The platforms are parented by a null object so that they can rotate as a single entity.
Maybe you can try adding how much the platform moved each frame to the player’s position. This would require that they aren’t parented to each other. I’ll write your script so you can try this.
public GameObject player;
public Vector3 lastPos = Vector3.zero;
public Vector3 changeInPos = Vector3.zero;
public bool playerAttached = false;
void LateUpdate () {
changeInPos = transform.position - lastPos;
lastPos = transform.position;
if (playerAttached) {
player.transform.position += changeInPos;
}
}
void OnTriggerEnter () {
if (other.gameObject == player) {
playerAttached = true;
}
}
void OnTriggerExit () {
if (other.gameObject == player) {
playerAttached = false;
}
}