For the game I’ve been working on, we’d like to have a small train/trolly type platform that the player should be able to get on and off of on will, and be able to walk around inside it while it’s moving.
For a basic, one-direction train, this is pretty easy. I simply issued a Transform.Translate to both train and player, and it worked flawlessly. Along with a trigger box to keep track of if the player was inside or not. If the player is inside, the player moves with the platform. If the player jumps off, the platform goes on ahead, and the player gets left behind.
But, we need the trolley to be able to go up hills and around corners. Since the player is in direct control of where the trolley turns, and how fast it’s going, we decided to go with some triggers… a trigger at key points on turns to tell the trolley when to turn and by how much. The trolley itself moves just fine up the test hill we have, but we’re having problems keeping the player on top of the platform.
One of the main issues is that the trolley uses a local move command (to simply move forward or backward) to simplify it. However, since the player is able to walk around on the trolley, this can’t be given to the player, so we’ve tried two different things:
1: We tried to give the player global move commands in an attempt to have him keep up with the trolley. This would work fine if we could get the math to work for us. The idea was to take the angle the trolley was facing and give the player move commands based on that angle. However, I’m unsure of how to do the math. I have a basic script that works (works as in, taking the angle of the trolley and giving the player a direction and speed based on that angle), but since the math is wrong, the player gets left behind each time the trolley goes up the hill.
2: A parent/child relationship that’s maintained so long as the player is boarded on the trolley. This works, except that since the trolley’s direction is changing depending on where in the level it is, the player will almost always rotate to face the direction the trolley is facing the moment he touches the trolley. I don’t mind if the player rotates with the trolley afterward (if anything, that’d be kind of nice), but the player suddenly rotating in this manner at the very instant of entry is unforgivable (makes it very difficult to board the trolley, if nothing else).
I’d like to make note that we plan on there being multiple trolleys that the player should be able to get on and off throughout the level, so a permanent parent/child relationship would be out of the question (I’d think so, anyway).
What I’d like to ask, is if there are any suggestions on how to make either of these ideas work, or if there are suggestions on other ideas.
If there’s a way to basically overwrite the very first frame of rotation, upon entering a parent/child relationship, that would be grand. I’ve looked around on the forums, but couldn’t find what I was looking for. I don’t want to stop the player from rotating with the trolley entirely, simply to not cause the player to instantly rotate to face the front of the trolley whenever he tries to board it.
Both my partner and I feel like we’re missing something really basic. Could anyone help point us in the right direction?