top of page
Installation

Important Notice

This is the online documentation page of the latest release : version 1.7

This documentation is also available offline, check into your asset folder.

 

Keep in mind that you can reuse this product for any commercial or non commercial projet. 

Any modification is allowed but please keep a link to this asset somewhere and don't hesitate to send me small video of your project, I will post it on Youtube.

 

Asset is using only Unity native 2D objects integrate from version 4.3. I mean sprites, physics and all elements using 2D suffix if possible. 

This way the asset is fully optimized for 2D. For now 2.5D is not supported (render 3D mixed with physic 2D) but I will work on it as soon as possible.

Stay tune!

 

All values are expressed in meters, kilograms and seconds (position, velocity, mass...).

This is the convention of most physic engines, that's why we respects this.

You will have to scale these values to fit your needs if needed.

All visible settings are serialized, undoable and prefabizable.

 

Animations are using new animation mechanism. You'll have to make sure you are using new Animator component. 

Notice that all animations names corresponds to an AnimationState inside the Animator and not a key name.

Installation

Asset is a complete project template. This allows you to build a game from scratch with no coding at all, just by using provided prefabs and scripts.

You can customize behavior easily by tuning values accessible in UI.

For more advanced users having some coding knowledge, it is also possible to customize behavior in a more advanced way, by using provided samples scripts and toolkits.

Please have a look on my Youtube channel for tutorial and demos if you can't get enough information here.

 

Some important projects settings are provided inside ProjectSettings folder : InputsManager, TagManager and Physic2DSettings

Please use them directly (overwrite into your project folder) or update your own settings to make sure everything is correctly configured.

Have a look a script execution order, this must match AP2D project setting too.

 

Load the Basics level and make sure everything works well. You can have a tour on other levels too and see what is available.

 

Normally you should not reference directly any provided resource in your game (sprite, animation, prefabs, animator etc...), because these may be updated/deleted during new versions and this could break your game. Instead you must duplicate each resources and put it in your own game folder. Then customize these resources at your will : settings, sprite, animation, fx etc....The only thing that you do not need to duplicate are all the scripts as they should be always compatible from one version to another. 

 

Please delete all the files of the package just before updating to a new version to avoid error (as some files are moved from one folder to another). Warn me if any mistake happens at this time.

CharacterMotor

CharacterMotor

This script offers same capabilities of classic CharacterController but exclusively for new Physic2D engine.

It is responsible for handling collision detection properly when moving the character. 

For now it is only compatible with BoxCollider2D, so you must add one to your game object before using this script.

 

Currently collision detection is done using ray casts in Physic2D world. 

This is an approximation as you don't detect collisions on entire box volume, so you can get drawbacks but in common case this works very well for 2D platformers. 

You must be aware of this when designing you character and your level.

All of this is well explained into this nice article.You should look at it, even if AP2D do not use exactly the same principles.

A ray has a starting position (represented as a square) and a ending position.

The small sphere is used to check the intersection with the box collider, indeed each ray will try to prevent penetration inside the collider.

Remaining path, after the sphere, is called extra distance, this is only for detecting surrounding environment and this is often used for scenaric purpose.

In this example we use two rays for detecting ground/ceiling and three rays for front/back walls.

 

Finally keep in mind that a ray detects collisions only along its path, so take care with your environment or you may experience penetration issues. 

Add more rays if needed or tune your collisions to prevent this.

 

Configuring the rays can be a complex task, that's why you should use the AutoBuilder feature. 

Default settings are well suited in most situations so you should keep it as this. 

Ask for help if needed, I can help you in configuring your rays for you specific character.

 

If needed you can adjust positions in editor, each ray can be grabbed and moved freely. 

You can also adjust the Extra Distance, this is only used to gather environment information around character. 

Ground skin width should always be near zero otherwise you character may float in some cases.

  • Rays : list of rays used for collision detection

    • Position = local position of ray relative to game object transform

    • Penetration = distance between sphere and square, you should never change this value, this is computed for you

    • Extra distance = distance to add after the sphere for detection surrounding environment

  • Velocity => current velocity of character (in m/s)

  • Face Right => tells if character is facing right, must be valid at init

  • Ray Layer => collision filter layer used by the rays

  • Debug Draw => enable debug drawing in Scene view, this information is serialized

  • Auto Builder

    • Ray Count X = number of ray along X axis

    • Ray Count Y = number of ray along Y axis

    • Extra Distance = extra distance to add for each ray

    • Ray Box Scale X = scale factor to apply to box collider for positioning rays along X axis

    • Ray Box Scale Y = scale factor to apply to box collider for positioning rays along Y axis

    • Rebuild = launch rebuild process

Finally if you want to use it in your script, update motor linear velocity (rotation is not supported for now), then use the Move() API.

The character will move using its current velocity and will stop properly on any detected collision along path. Linear velocity will be recomputed by the way. 

We will try to correct penetration errors too, thus by pushing character in right direction.

Lots of service are available, as getting collisions information during last move, changing collision filter, scale the rays...

Notice that triggers colliders are ignored.

Please have a look at source code if interested.

bottom of page