• Stars
    star
    1,032
  • Rank 44,644 (Top 0.9 %)
  • Language
    C#
  • Created about 11 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

More Repositories

1

Nez

Nez is a free 2D focused framework that works with MonoGame and FNA
C#
1,799
star
2

TouchKit

Gestures and input handling made sane for Unity
C#
896
star
3

GoKit

Lightweight tween library for Unity
C#
583
star
4

RecyclerKit

Object pool manager for Unity
C#
363
star
5

TransitionKit

Modular, extensible transitions in scene and between scenes
C#
300
star
6

SpriteLightKit

Blended lighting system for Unity that works with standard Sprites
C#
227
star
7

StateKit

Dead simple, lightweight "states as objects" system
C#
220
star
8

ZestKit

Tween library for Unity. The best of GoKit and GoKitLite combined in an easy to use API
C#
156
star
9

Nez-Samples

Samples and demos of various Nez features
C#
148
star
10

zig-ecs

Zig
144
star
11

P31UnityAddOns

Mostly defunct. Features were added and components broken out in the *Kit repositories.
C#
142
star
12

zig-upaya

Zig-based framework for creating game tools and helper apps
Zig
124
star
13

MessageKit

Decoupled message sending system meant as a replacement for SendMessage and its variants.
C#
122
star
14

zig-gamekit

Companion repo for zig-renderkit for making 2D games
Zig
103
star
15

CameraKit2D

Framework for creating 2D camera systems
C#
95
star
16

zig-renderkit

Zig
54
star
17

zig-flecs

C
51
star
18

GoKitLite

A super duper lightweight tweening library for Unity
C#
51
star
19

SoundKit

C#
45
star
20

Unity-Ripgrep-Search-Tool

C#
42
star
21

P31TaskManager

General purpose task manager that provides a lot more control and power than a standard coroutine
C#
35
star
22

via

V 2D game library
V
29
star
23

UnityCgShaderTutorials

Source code for the Unity Cg Shaders tutorial series on YouTube: http://www.youtube.com/playlist?list=PLb8LPjN5zpx1tauZfNE1cMIIPy15UlJNZ
C#
27
star
24

V-C-Wrapper-Generator

Helper for generating Odin and V wrapper code from C source
C#
19
star
25

Simple-ECS-Sharp

C#
18
star
26

ecs-lua

A simple, hybrid ECS
Lua
17
star
27

zig-miniaudio

Zig
17
star
28

SpriteKit

DEFUNCT: Unity now has 2D tools built in. This is now not maintained.
C#
15
star
29

PaletteKit

Helpful editor classes for importing and displaying color palettes
JavaScript
12
star
30

LearningUnits

C#
10
star
31

Odin-Sublime-Text-Plugin

Python
9
star
32

ImGuiGL-Renderer

C#
9
star
33

zig-vulkan

C++
5
star
34

egui_curve_tool

Rust
4
star
35

zig-aya

Zig
4
star
36

App-Engine-Task-Manager

Python
3
star
37

Odin-Libs

C
3
star
38

v-temp-modules

V
3
star
39

zig-fmod

Zig
2
star
40

Hugo-Helper

macOS app for managing a Hugo website
C#
2
star
41

prime31.github.io

HTML
2
star
42

fips-flecs

fipsified version of the Flecs ECS
CMake
1
star