Unity Game Development Cookbook by Paris Buttfield-Addison

Unity Game Development Cookbook by Paris Buttfield-Addison

Author:Paris Buttfield-Addison
Language: eng
Format: epub
Publisher: O'Reilly Media
Published: 2019-03-12T00:00:00+00:00


Add a PlatformRiding component to the player character—that is, the object that has your CharacterCollider.

Play the game and jump onto an object that has a MovingPlatform component. Your character will be carried with the platform. Additionally, if you get off the platform and then stand in its way, you will be pushed by the platform as it moves into you.

Discussion

This recipe performs two different tests to see if the CharacterCollider needs to be moved:

First, it calculates the size of the capsule that the CharacterCollider occupies, and then asks Unity’s physics system to check to see what colliders also occupy this space. If a platform is pushing into the character, the two colliders will be intersecting, albeit by a small amount.

If the colliders are intersecting, then we ask the physics system to compute the depenetration vector. This is the amount of movement that it would take to move the player so that the two objects aren’t overlapping. It’s then a simple matter of moving the player by that vector, which means that it moves “out” of the platform; the net result is that the player is pushed away from the platform.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.