Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Additional Player Actions #55

Open
meghapants opened this issue Jun 21, 2016 · 11 comments
Open

[Request] Additional Player Actions #55

meghapants opened this issue Jun 21, 2016 · 11 comments

Comments

@meghapants
Copy link

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!

@cjddmut
Copy link
Owner

cjddmut commented Jun 21, 2016

That's because the current motor architecture isn't that great at states working together :p The motor originally just handled basic character locomotion (moving, jumping, and dashing). Ladders were an awesome addition by someone else but are somewhat placed on the previous architecture. What should happen, ideally, is a clear cut distinction of what mode you're in and that mode's functions get called. So you would be in locomotion mode, dash mode, ladder mode, or rope mode (and ideally any other modes can be added here).

Arguably picking up and throwing don't need to exist inside the motor (as it the actions don't have anything to do with moving) but once you've thrown then you can attach to the rope.

@meghapants
Copy link
Author

I suppose that's very true - I was just looking at what already existed and was very trapped within that headspace. :P I was thinking about just reversing the principal of the moving platforms so that rather have the motor attach to something else, the something else attaches to the motor. But you're right, I don't have to do it that way.

For the most part I've figured out which steps I need to take to set up sprinting, it's just a matter of where. This is what I've managed to put together so far for sprinting:
-Added sprint definition into Input class in Globals.cs
-Added checking for sprint input (Fire3) in PlayerController2D.cs
-Added (currently empty) sprint function to PlatformerMotor2D.cs
-Added public bool IsSprinting() to return the motor state as sprinting to PlatformerMotor2D.cs
-Added Sprinting to enum MotorState in PlatformerMotor2D.cs

And this is what I think I still need to set up:
-Sprinting should only be allowed if grounded (Line 1607 PlatformerMotor2D.cs)
-Create enum for sprinting states, such as on ground, on slope and on water
-Grab and apply movement speed if sprinting from some combination of GetSpeedAndMaxSpeedOnGround (line 2598) and UpdateVelocity (line 1371) and ApplyMovement (line 2389)

I'm just not sure what the most effective way to do this would be. I'm a little lost in the very long PlatformerMotor script. Any help is appreciated (even if it's just me talking through the problem here).

@cjddmut
Copy link
Owner

cjddmut commented Jun 21, 2016

It sounds likes you're on the right path. All sprinting is is the change of acceleration, max speed, and deceleration. Being able to query for animation purposes is nice too.

The two functions that really care about those properties is

GetSpeedAndMaxSpeedOnGround (2580)
ApplyMovement (2371)

If those two functions picked the right values depending on if you're sprinting or not then that'll do it (and a query for IsSprinting should be sufficient). There's also the consideration on if sprinting is allowed in the air, which is just changing the speed, acceleration, and deceleration values when in the air too.

And yes the motor is very long, way to long :) When I get the time to come back to this package I want to refactor it into something more manageable.

@meghapants
Copy link
Author

Awesome, thanks a lot. It helps to know I'm heading in the right direction! I can't wait to see what additions you will make in the future! I've read the license over but I also wanted to clarify that as long as the license is contained within my project, your controller could be used in a commercially sold game that I make?

@cjddmut
Copy link
Owner

cjddmut commented Jun 21, 2016

Yea that's fine. Basically you can't take the controller and just sell it as a package.

@meghapants
Copy link
Author

Hey, sorry to bother you again. I got sprinting and crouching working! I was wondering if you might have a suggestion for this dilemma... I'm using the 2D controller on a 3D object strictly for the art style (going for a 2.5D style). I created some animations for my player character - for example, the idle turns to the camera and waves. Because the motor is built for 2D and mainly for sprites, any rotations on the Y and Z axis are ignored and the model snaps back to the default position. Can you think of a way we could get around this for a few animations?

@cjddmut
Copy link
Owner

cjddmut commented Jul 16, 2016

Set your visuals on a child object and you'll be able to rotate or animate
however way you'd want

On Fri, Jul 15, 2016, 5:56 PM meghapants notifications@github.com wrote:

Hey, sorry to bother you again. I got sprinting and crouching working! I
was wondering if you might have a suggestion for this dilemma... I'm using
the 2D controller on a 3D object strictly for the art style (going for a
2.5D style). I created some animations for my player character - for
example, the idle turns to the camera and waves. Because the motor is built
for 2D and mainly for sprites, any rotations on the Y and Z axis are
ignored and the model snaps back to the default position. Can you think of
a way we could get around this for a few animations?


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#55 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC3Ab-D3nKzryes1x181_HhH4_peDmFFks5qWCw-gaJpZM4I6SOy
.

@meghapants
Copy link
Author

Ugh. Such an easy answer. I was way overthinking it - but it also helped me find a major flaw in the way I set up my prefab. I was pulling my hair out because the Animation script was working in your test scene but not with my prefab. Thank you.

@themrangel
Copy link

Wow @meghapants, I was also thinking about expanding this awesome controller with swinging, but I don't know where to start (I'm not so experienced). I treated a rope (made of little squares with hinge joints between them) as a ladder, and it works, but the player moves so laggy. Any idea?

@llafuente
Copy link
Contributor

I try to implement those things in the past for this library, after working on it I just abandon it because it has no concept of movement and adding something is very uncomfortable.

Water & grab box (box2 branch): https://github.com/llafuente/Unity-2D-Platformer-Controller/commits/box2
There are other staff in other branches fell free to explore :)

If you want rope implementation:

@themrangel
Copy link

Thanks a lot @llafuente, I'm going to check this. I hope to understand what you did here and how to implement it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants