First up, apologies for this post being copied/pasted from the Unity Questions forum. I find that's not a particularly heavily visited site, nor particularly well suited to discussions.
This is sort of an open ended question I suppose, as I'm looking for advice on the approach as much as a specific technical solution.
I'm building a first-person game revolving around a hot air balloon (I've not got around to a devlog yet, but I will do once I have this problem sorted out). I've built a basic craft, and I've got the whole buoyancy/movement system working really nicely. It's all built in Playmaker, but the principles are the same regardless.
The key problem I'm having is: When the player is inside the cabin, and the craft is moving laterally, the player will occasionally suddenly pop outside of the craft and fall to the ground. Here's a video of it: http://puu.sh/qRpNS/66d44f8d1b.mp4 (Happens at the very beginning of the video, and again at around 16 seconds)
This is the construction of the craft:
So the craft is basically constructed from two rigidbodies objects, the balloon, and the cabin, and they're attached with a fixed joint. I've previously used a short chain of character joints, but I've pared it down to a fixed joint for now while I figure out this issue.
The craft achieves buoyancy by applying upward forces to the balloon every frame. It travels laterally by applying horizontal forces every frame to the BalloonRigidbody and the CabinRigidbody, based on the craft's position on the map. This works really, nicely, allowing for very natural feeling travel.
The cabin mesh itself is too complex to serve as the collider due to Unity's new limits, so I've got a collection of primitive shape colliders, with kinematic rigidbodies, to serve as the collision for the player. That's marked 'ColliderMaster' in the diagram. These are the only physics objects the player is set to collide with, as set in the Physics matrix. You can see these colliders in the image below.
When the player enters the balloon, they pass through the Cabin Trigger (a trigger volume), which then parents the player to the ColliderMaster. The ColliderMaster has a script that updates its position every frame, placing it at the position and rotation of the CabinRigidbody. I've got it set up this way as, without parenting the First Person Controller, it jitters all over the place, and so I read somewhere that this sort of setup, parenting the player and updating the position of the colliders every frame, independent of the physics simulation, was the way to go, and it's certainly been the most successful.
So we come to the problem again, which is that when the craft is moving laterally, eventually the player will suddenly be outside of the craft, falling forever. It appears to be that the player will only fall out of the trailing side of the cabin, ie., if the balloon is moving 'left', the player will fall out of the right side.
Here's another image showing the craft and position of the player (at the right, the speaker/camera icon), moments before suddenly being ejected:
Some things I've ruled out:
- The player is not accidentally passing out of the CabinTrigger, causing the player to un-parent itself from the colliders.
- Thicker colliders makes no difference
- I tried the Standard Assets Rigidbody Controller too, but it just introduces a host of other undesirable problems, in that it interacts with the craft and can push it around etc.
I feel like there's some fundamental issue either with the way I've constructed the craft/colliders, or with the way I'm dealing with the player. I wondered if maybe using physics for the balloon was even the wrong way to go about it, but it seems like surely that should be feasible.
If anyone could offer any advice I'd appreciate it!
Cheers, Nate
P.S. As an extension to all of this, aside from falling out of the cabin, the FPController is also prone to applying unwanted movement to the cabin as you move/bump around inside, ie. you can sometimes make the cabin rotate around the Y axis by moving left and right. I wonder if there's a broad solution that also includes the fix for this problem?