Coder Social home page Coder Social logo

cjddmut / unity-2d-platformer-controller Goto Github PK

View Code? Open in Web Editor NEW
864.0 864.0 161.0 3.48 MB

A customizable 2D platformer motor that handles mechanics such as double jumps, wall jumps, and corner grabs. Includes a player controlled prefab that can be dropped into any scene for immediate support.

License: MIT License

C# 100.00%

unity-2d-platformer-controller's People

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  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

unity-2d-platformer-controller's Issues

Throwing

Hi, I would like the player to be able to throw something like a ball at something. Is this possible in Unity 5+?

Ladders not working with moving platforms

Hi,

I've been trying to use moving platforms and ladders in the same scene. I found that when Moving Platforms Layer is set to Moving Platform and my characters is on ground, it cannot climb the ladder.

If I jump and climb it, things work fine, but if I'm touching the ground, it seems like the character keeps constantly entering and leaving freedom state.

I've tested a few things and I think the problem is somewhere around these lines in function CheckGround, in PlatformerMotor2D.cs:

if (closestHit.collider != null)
{
    surfaces |= CollidedSurface.Ground;

    if (IsUserHandled())
    {
        FreedomStateExit();
        DisableRestrictedArea();
    }

    if (_collider2D.bounds.center.y - closestHit.centroid.y < minDistanceFromEnv || forceDistance)
    {
        transform.position += (minDistanceFromEnv -
        (_collider2D.bounds.center.y - closestHit.centroid.y)) * Vector3.up;
    }
}

What should I do?

(Attached a video demonstrating the issue)

Ladder issue.mov.zip

Unity 5.3 OWP

The one-way platforms don't work with Unity 5.3 anymore. It seems that Unity changed how the PlatformEffector works in the latest version.

Can you please update the asset?

[Question] Jump and Dash

Hi there, I was trying a few moments ago and I'd like to go if is it possible to jump during a dash, just like the Megaman X games. If so, what should I change in the code?

There is a slight delay after pressing left/right key before character actually begins movement

First, thanks for this wonderful controller! It's just programmed brilliantly, and should be simple to modify for what I need it to do. But I'm running into just one issue.

I'm just using the Basic Player Controller prefab. When I press left or right, the character does nothing for about a quarter of a second, then begins accelerating. Just tapping left/right does not result in the character moving at all, the key must be held for >.2 seconds (as far as I can tell). This even happens when Time to Ground Speed is set to zero.

Why is this and how can it be fixed?

That little step...

Whenever you jump in a direction and lands on a platform, the player does a little step forward before stopping. This is really bad for precision platforming and should be possible to disable... Pretty please?

Fire / Combat implementation

Hi,
Nice job here ! Thank you !

Not a 'bug' but how can we implement firing action ? it would be nice to have to be a complete platformer controller !

Limit bounds doesn't update Z-axis

I'm prototyping a 2d platformer where you can switch to another world when pressing a key. In the Unity side I'm using a function to translate the player object to another Z-axis coordinates, keeping XY the same.

The problem: When the player object is translated to another Z coordinate, some limit bounds used in the PlatformerMotor2D to manage collisions aren't updating to the new coordinate. If you do some jumping, as soon as you touch the ground, the player object is translated back to the original position.

Issue gif

Character does not move in Unity 5.3

Hi,

I just opened my project using this system in Unity 5.3 and character is not able to move while on ground. If I jump I can move but otherwise not. Also one way platforms etc does not work in 5.3

Also do you plan to add 5.3 2d effector support?

No movement on key push for short period of time.

Even using the default code that is provided with the example, the character, whether its ninja or my own will not move for a short period of time. This means I can't tap the A/D keys for movement I have to hold them and it is very innacurate.

Why is this occuring, how can I fix it?

Unity 5.3.0 Unable to Walk

I recently updated to unity 5.3.0 personal edition. Character Controller is unable to move left and right when slopes are enabled.

Ladder / Climbing area implementation

Add a new motor state : OnLadder
Add a flag to detect if the motor overlaps a climbable collider
Ability to set directional movement, IE: Vertical, Horizontal, both

Collision

Hello!

Great script! It has alot of usefull features. Although I am having some trouble getting the collision to work. I put some platforms on my scene, set thier layer to "platforms", and on the PlatformerMotor2D I set the enviroment layer also to "platforms" but there is no collision and the player just falls.

I am using your prefab with a custom sprite inside it.

Any help would be awesome!

Cheers

Jumping under a slope while moving

I was moving to the left, hit the slope from the bottom and got stuck inside.
I tried to get out, but I couldn't do it.

YouTube Video
YouTube Video (I uploaded another where you can see the movement I did)
GIF

Here's the project if you need it
https://mega.nz/#F!H5ZnkIbS!4h971dTQ9yDoXRCTVCcxpg

Also, how can I make the player "fall smoothly under a slope" like in Super Mario World...
YouTube Video

...so it doesn't stop for a second like this?
YouTube Video
GIF

I'm using Unity 5.1.1f1 32-bit.

[Request] Modify dash gravity scale

Hello,

Is it possible that you add a property to modify the gravity scale during the dash?
In our project we want the player to be affected by gravity while he is dashing.

Thanks.

WorldCollider and Plugin system.

Hi @cjddmut,

I already have implemented Push/Pull boxes and Water.
But before refining all my implementations (ladder included) and before adding ropes.

I think we can discuss some mayor changes that I will introduce and why...
I hate that all logic is in a single file with all private. Everything is private for no reason.

I would like to have a WorldCollider/PlatformerCollider component, that manage all basic collisions (ground, moving platforms, walls)
And the all sort of plugins. Jump, Dash, Water, Ladders on top as extra components

I have a POC at isolation branch, here is the diff: develop...llafuente:isolation

Also the plugin system wich i use for developing water and grab. it add a silly hook to velocity but works and can be extended when a new plugin requires a new hook.

POC: develop...llafuente:box2

Any suggestions?

Ability to customize corner grab collision area

Currently, the corner grab is valid when any part of the Player collider is touching. It would be a nice feature to customize this collision range so, for instance, only the top half of the player's collider was a valid area for corner grabbing.

Delay between input and movement starting

I seem to be having an issue where the standard 'Basic Platformer Controller' prefab has a noticable delay between input and movement. This isn't particularly noticeable when you're in the air (edit: actually, it sort-of is if you start with a standstill jump, then start holding a direction midair), but when you start from a dead stand-still, there's a good amount of time where you're holding the button, but having started moving yet.

I know that's not much to go on, so let me know if there's anything more I can provide to help.

This is an awesome controller. Has everything you could want - power-curve jumps, doublejumps, wall-slides, wall-jumps, etc. And tons of great information too.

EDIT: Aha - INPUT_THRESHOLD in globals. I thought I checked that file before submitting this - sorry!

Moving from walkable slope to wall causes a bounce and stick to wall

Moving from walkable slope to wall causes a bounce and stick to wall. I doubt this is intended.
Each time the player moved against a wall from a slope he bounced up instead of standing still.

He does this even if the minimumSpeedToMoveUpSlipperySlope is set to a large number to stop the player from attempting to climb slopes that he is not able to.

Everything else works great even with procedurally generated meshes/colliders!
Awesome work indeed!

No instantaneous movement?

Even with Time to Ground Speed set to zero, it still takes briefly holding, not tapping a key to get the player to start moving. This seems counter-intuitive to most old school platforming. I've modified the motor in lots of ways and tinkered with the source but cannot fix this.
Otherwise the controller is everything one could dream of.
Thank you greatly.

P.S. you guys should have a paypal donation box open

Moving platform and problems getting stuck at slopes

When the motor have available the moving platform option, assigning a layer mask to it, the player get stucked when trying to get up/down slopes. Everything works fine with the slopes when no layer mask is assigned.

Help setting up?

I apologize if this seems over simplistic but I cannot figure out how to open or apply this project at all...A minor tutorial for the skill-inept would be really useful. I cannot drop the prefab into a scene, it just won't allow it. Would it be easiest and is there a way to just import all of your animations into an original scene and apply all scripting to it?
Thank you!

P.S. sorry again if this is too obvious a question, but me and my wife have been running into brick walls attempting 2d game developing as a hobby for 2 years now and this could really be the breakthrough we need.

Simulate AddForce

Hi,

I working on a water bouyancy, currently I just modifying the velocity, to give the bouyancy sensation but the result is not realistic but it's ok, but i would like to try a more realistic aproach if possible. So I'm going to switching to archimedes law that ends in AddForce to the motor...

How can I simulate AddForce with the current motor code??

Implement mode system in PC2D

The idea is to have clear separation to the different 'modes' that have popped up during development.

Right now there is a normal, dashing, and ladder mode. A more clear distinction between these in the code could make it easier to read and less prone to bugs.

Scale X flip breaks collision on slopes

I saw this before the animation demo was added to the repo. It appears that flipping the Transform with the PlatformerMotor2d script will sometimes push the character through the ground on slopes. My tests have multiple slope angles (1/2 and 1/3 slopes) which may be where the issues is coming from.

I solved this by flipping the visual child transform instead, but it would be nice to flip the entire parent.

[Request] Additional Player Actions

Hi,

First of all, thanks for making this awesome platformer controller! I'm pretty new to programming but I've been able to deconstruct a fair amount of what you've done with it and it has been a fantastic starting point. It's very smooth and feels great.

I've been trying to implement a few of my own features but because of my limited programming experience I've been struggling a little bit. This is what I've been hoping to add:

-Sprinting
-Picking Up
-Throwing
-Crouching
-Rope swinging

I think I've been making some progress on sprinting, because it's the same principal idea as moving, just faster. Same goes for crouching really, but half movement speed. The biggest challenges I'm facing are picking up, throwing, and swinging.

The ladder script has given me a good basis for ropes, but it's very stationary. Ideally I'm trying to have the player throw an object to a hook on the wall, then jump onto the rope and be able to swing from side to side, and climb up and down on the rope.

I've determined the easy parts - creating new motor states and receiving the proper input for the required actions. With the combination of scripts I'm just a little lost trying to figure out how they all work together. Even just some direction on where to work these new features in would be greatly appreciated!

Missing definition

When I boot up Unity 3D, this error appears in the console:Assets/PC2D/Editor/PlatformerMotor2DEditor.cs(349,24): error CS0117: UnityEngine.Physics2D' does not contain a definition forqueriesStartInColliders'

Falling through sloped one-way platforms with Polygon/Edge colliders

While walking on one-way platforms, if the player walks up a sloped platform, they will immediately (within one or two frames) fall through it. This only happens if the platform uses a Polygon or Edge Collider. Box Colliders are fine, and walking down sloped platforms works correctly with all kinds of colliders.

I've put together a small example scene using the stock PC2D Player prefab, Tiled Map Editor, and Sean Barton's Tiled2Unity.

Project (Unity 5.1.1f1 / 2f1): http://chicago-lollie.com/protoplatformer/git/SlopedOneWayPlatforms.rar

I'll note, I'm not sure if this is a PC2D issue or a Unity issue. Unity's Manual entry for PlatformEffector2D mentions a "Surface Arc" property, but this doesn't appear to be available in Unity 5.1.1f1. For all I know, that property could be the solution to this issue.

Simple Gravity Implementation

Hey. I'm working on a game called NET, a 2D platformer which is on the surfaces of 3D objects, and in order to make it work I need to use a modifiable gravity. I have a simple 2D controller already created for a deadline, which I think I will apply the principles of to this project to allow the programmer to select the four cardinal gravity directions - up, down, left, or right - which can be used as a baseline for future revisions. But before I go ahead, I'd like to pitch my idea and see if it seems viable. Here's what I did in the original controller:

The original controller contained a few key elements. It was fed a gravity constant, a gravity direction, and using the direction, it referenced two Func<Vector2, Vector2> fields: VecRotate, which rotates from down to the set gravity direction, and InvVecRotate, which rotates from the set gravity direction to downward.
Any time a Vector2 needed to be referenced in the script, it would be preceded by one of these two Funcs. For example, the control code went like this:

void Update() {
    Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
    Vector2 modified = VecRotate(input); // Turn the input so that it matches the gravity, ex. if gravity faces right, the horizontal becomes the vertical, etc
    rigid.velocity = modified;
}

It's a bit simplified, but that's effectively the idea - and that's the principle I plan to apply to the four-direction gravity version of the PC2D. And more skilled programmers, in future builds, can use the same framework; instead of four cardinal directions, just have the VecRotate and InvVecRotate properties refer to more general Funcs for the angle.

Thoughts?

[Question] Getting characters to act as moving platforms while also inheriting movement from other moving platforms

I'm working on a game that requires there to be moving entities or objects that act as moving platforms. But those entities need to also be affected by moving platforms like the player is. This means that the player could toss a stack of boxes onto a moving platform, and the stack will all just move along nicely.

So technically this means that these entities need to be in the MovingPlatform layer. When I move them into that layer they detect themselves for collisions and just float in the air basically unable to move anywhere. (Right now I'm using the Simple AI Ninjas to test this)

I've tried going through the PlatformerMotor2D script and doing a little trick. I switch the layer to a new layer that I called TempLayer before running all the checks, and then switch back to the original layer. This now makes the characters stay in a falling state with the falling animation and "technically" causes their vertical speed to increase(unlike before when they would stand in the air) but they still do not fall, and seem to be detecting a collision with themselves.

If someone could point me in the right direction I will run with it and I will share what I come up with.

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.