Git Product home page Git Product logo

charactercontroller2d's Introduction

CharacterController2D

CharacterController2D is similar to the built-in Unity CharacterController component. It has a similar API (mainly a move method that takes a delta movement) and provides a firm base with which to make a super solid controller using Unity's 2D system.

A simple demo scene is included along with a few Spelunky sprites (which obviously should not be used in your game!). An overview video showing how to get started is available on the prime31studios YouTube channel here.

Demo Scene

The included demo scene is minimal to keep things as simple as possible. It has very basic input detection (using the arrow keys to move, jump and fall through one way platforms) and a simple character sprite/Animator setup. This should be simple enough for anyone with a rudimentry knowledge of Unity to read through and understand.

Basic Setup

Setup is pretty simple: drag the CharacterController2D onto your player/enemy GameObject and set the platformMask in the inspector to contain any layers that you want the player to collide with. If you will be using one way platforms, you can set the oneWayPlatformMask as well. Note that one way platforms should be EdgeCollider2Ds. ProTip: make sure your player is on a separate layer than your platforms so that she doesn't try to collide with herself! You will also want to make sure you BoxCollider2D is centered and has a zero horizontal offset. Flipping requires setting the scale.x to -1 so a horizontal offset other than zero will result in the collider jumping around.

You can then tweak the totalHorizontalRays and totalVerticalRays to your liking. When in the editor rays will be drawn with Debug.DrawRay so that you can make sure the ray resolution is appropriate for your smallest platform size. To turn off ray debugging just comment out the #define DEBUG_CC2D_RAYS line at the top of the CharacterController2D.cs file.

To move the player around just call move and provide it a delta movement (the physical distance the player should move this frame). You can subscribe to the onControllerCollidedEvent to be notified of all collisions if you need them.

In order to be able to receive trigger events (onTriggerEnter/Stay/Exit) the CharacterController2D needs to be told which layers it should interact with. Select the layers that should fire trigger events via the triggerMask field in the inspector.

License

Attribution-NonCommercial-ShareAlike 3.0 Unported with simple explanation. You are free to use the CharacterController2D in any and all games that you make. You cannot sell the CharacterController2D directly or as part of a larger game asset.

charactercontroller2d's People

Contributors

prime31 avatar jamiltron avatar jellybit avatar sjoshbrown avatar jceipek avatar

Watchers

Ian Zhong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.