Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411275 Posts in 69323 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 08:54:38 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Hot Air Balloon sim- Dealing w/ unreliable rigidbodies, force, FPS controls etc.
Pages: [1]
Print
Author Topic: Hot Air Balloon sim- Dealing w/ unreliable rigidbodies, force, FPS controls etc.  (Read 1414 times)
Nate_G
Level 1
*



View Profile WWW
« on: August 28, 2016, 06:38:45 AM »

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?
Logged

Overpass
Devlog
A hot air balloon exploration game.
NoLocality
Level 1
*


AssetsAssetsAssetsAssetsAssets...


View Profile
« Reply #1 on: August 28, 2016, 07:21:26 PM »

Is it necessary to have the player active while in the balloon?  Is it necessary for the player to be able to move around while in the balloon?

If not then I would destroy the player object completely when entering the balloon and instantiate a placeholder that looks like the player as if he was riding it, then when the balloon ride is over instantiate the player again.


If it's part of your game to walk around in the balloon cabin then maybe check what kind of movement the player controller script is using (does your player object have a rigidbody?), in my experience if your movement script uses something along the lines of transform.position += etc... then it might not play so nice with rigidbodys.

If this issue get's too time consuming too solve perhaps consider having rigidbody-based player movement if you don't already.


Good luck with that and hopefully it's one of those ones where the answer magically comes to you out of nowhere.
Logged

darkhog
Level 7
**


Dragon Agent


View Profile
« Reply #2 on: August 29, 2016, 04:53:37 PM »

How about making player itself a rigid body and write controller that drives player using forces? Then when player enters the cabin instead of parenting him to it, attach him using a joint (fixed or not).
Logged


Be a computer virus!


I cannot C well, so I stick with simpler languages.

There are no impossible things, there is only lack of skill.
bateleur
Level 10
*****



View Profile
« Reply #3 on: August 30, 2016, 08:14:30 AM »

Basically what's going on is that Unity's PlayerController class is a horrible, horrible hack designed to make a very specific kind of game easy to implement. You're making something much more interesting, so PlayerController will cause you nothing but pain.

I would go with darkhog's suggestion and implement the player as a CapsuleCollider plus a Rigidbody with angular rotation locked for the X and Z axes. I wouldn't even bother with a joint attacking the player to the cabin. Update the player's position manually each frame during LateUpdate to get the dynamics you want.

Regarding NoLocality's transform.position comment: this is correct, but note that there is a better approach to this in the form of Rigidbody.MovePosition (and MoveRotation), which generate slightly nicer behaviour in some cases.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic