Giter Site home page Giter Site logo

matthew-j-spencer / ultimate-2d-controller Goto Github PK

View Code? Open in Web Editor NEW
1.8K 27.0 377.0 1.41 MB

A great starting point for your 2D controller. Making use of all the hidden tricks like coyote, buffered actions, speedy apex, anti grav apex, etc

License: MIT License

C# 100.00%

ultimate-2d-controller's Introduction

Ultimate 2D Controller

An updated, smoother version using standard Unity physics is on my Patreon.

A great starting point for your 2D controller. Making use of all the hidden tricks like coyote, buffered actions, speedy apex, anti grav apex, etc

Watch the video: https://www.youtube.com/watch?v=3sWTzMsmdx8
Play the game: https://tarodev.itch.io/ultimate-2d-controller

Leave a ⭐ if you found it helpful!

User guide:

  1. Set the player layer in the Player Controller asset located at Tarodev 2D Controller/Stat Presets/Player Controller
  2. That's it! Check the demo scene if you're stuck :)

Feel free to use the code in your production games. Attribution welcomed :)

About the 'Extended' controller (Patreon)

Converted to use standard unity physics, making it much easier to use and incorporate into your game.
It's even smoother than the current version.
Moving platforms & one-way platforms.
External forces (explosions, sword hits, bouncy... things).
Dash, double jump, crouch/slide.
Slopes.
Ledge sliding, grabbing & climbing.
Tilemap Support.
New input system support.
Fixed a bunch of bugs.
And of course better support.
Click here

ultimate-2d-controller's People

Contributors

matthew-j-spencer avatar zaidmermam avatar zure1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ultimate-2d-controller's Issues

What’s the Extended Source Code?

Hi there! I would really appreciate the info what to expect for the paid "Extenden Source Code"

Thank you very much for this and everything you do on YouTube!

How do I implement this?

I got the package, and I put it in my project, everything fine. Then, I put the Character Controller on my player, set the ground layer, and it's like falling in and out of the floor. I don't know quite what's going on. Can anyone help me? (I'm working on getting a video, I'll comment when I do.)

Put scripts in a namespace.

To avoid clashes with any other third party scripts please would you consider moving the scripts from the global namespace to their own?

Request for different game's character-like presets

Hi, I'm a subscriber of yours that just watched your video and had an idea to extend this repository.
As you showcased Celeste and Super Meat Boy are ones of the greatest games in terms of platforming and character controls. Wouldn't it be so nice for developers to achive nearly as much as these with your awesome 2D-controller?

I know that although the scripting and physics have already been solve, many developers could stugle with getting the right values for each of the many parameters in your Character Controller. Therefore why not taking the time among all who decide to use this solution, and those who find some cool values for your script parameters contribute with a preset file (the ones you can make in unity by presing the second button on the top right of any component) for this. It could have a Mario preset, a Celeste one, etc.

Please regard adding or creating these presets for your repository.

Deeply nested loops on collision detection

Right off the top wanted to say thanks for open sourcing this. Been reading through the PlayerController and learning a lot. I'll also concede that I spend most of my time with Javascript and Java, so not sure if the following concern plays out in C#.

It seems like there are some deeply nested iterations involved with collision detection and I'm wondering if dramatically impacts performance if, for example, you had multiple players on screen at once?

Loop layers

  1. Calculate collisions
_colUp = RunDetection(_raysUp);
_colLeft = RunDetection(_raysLeft);
_colRight = RunDetection(_raysRight);

Not an actual loop, but practically speaking occurs each Update()

  1. Run Detection
EvaluateRayPositions(range).Any(point => Physics2D.Raycast(point, range.Dir, _detectionRayLength, _groundLayer));

Iterates over each point returned from EvaluateRayPositions

3. EvaluateRayPositions

for (var i = 0; i < _detectorCount; i++)
{
  var t = (float)i / (_detectorCount - 1);
  yield return Vector2.Lerp(range.Start, range.End, t);
}

Iterates over _detectorCount, which is defaulted to 3 but looks toggleable.

Minimum n^3 complexity per Update() and potentially n^4 if, for example, you additionally called OnDrawGizmos() within Update() (thank you for the Gizmo function, btw).

All that said, being new to both C# and Unity I'm not chock full of refactor ideas. I assume most of these layers are necessary. Could you execute the RunDetection() calls in parallel with something like Parallel.ForEach? Something analogous to Javscript's Promise.all([foo(), bar()]).

Anyway, great work!

No Slope Support

Cant move up slopes and going down sloped spams the landing effects.

Character stuck in mid air

I got stuck here without the ability to move anywhere, can't jump. On inputs left/right the character just slightly tilts.
image

Fall through ground on spawn

First of all thanks for all your hard work! 👏

I got an issue that if the player spawn too close to the ground the player falls through.

PS: Can i use this in a project?

It's frame rate dependent..

When vsync is off, in focused view, my character jumps lower
If I enable vsync, my character jumps higher

Collision and Movement calculations don't take into account center of the character bounds

It's possible to offset the center of the character bounds, but they are currently not taken into account. The current calculations work only if the center of the bounds is Vector2(0,0).

I fixed it on a branch and will link the pull request, feel free to give feedback if there are any problems with the solution.

And thank you for this awesome character controller!

Ground Layer

I don't understand how to set the ground layer. The character moves just fine (seemingly), but I keep falling through the ground instantly. I have the ground placed and I made a layer titled _groundLayer but it doesn't work. I apologize if I'm just being an idiot and the fix is blatantly obvious, I'm a new developer and this is my first time trying to make a game.

And no I don't have the money to buy the patreon for the better code, and I'm not a skilled enough coder to convert the code in the free version to use rigidbodies.

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.