DemoProductions / fighter

2 stars 1 forks source link

A player gets stuck if the player is on top of another player #7

Closed ghost closed 9 years ago

ghost commented 9 years ago

Maybe the player should slide off the other player. Or we can do the easier implementation of having the character stand on top of the other's box collider for now. We can add a tag to tell if the object is a player or not

flip40 commented 9 years ago

Ah, good to know. Sliding would be best, I think, if we can.

ghost commented 9 years ago

What would happen if we just changed the BoxCollider around the player to be Circular or something like that? Along with changing it so that the player isn't treated as a floor. Will try later

flip40 commented 9 years ago

The player->player collision shouldn't actually have the same interaction as the floor:

    void OnCollisionEnter2D(Collision2D collision) {
        // if on floor, stop falling and reset jumps
        if (collision.collider.gameObject.name == "floor") {
            jumps = 0;
            yvelocity = 0;
        }
    }

So not sure why they stick, but it shouldn't be due to that.

I am a bit undecided on having a circular collider (having it on top makes sense, but not the entire collider). What I am indecisive on though was that I was planning to add frame by frame hurtboxes (which would possibly also double as new collision boxes, but that might be a third kind of frame by frame box if it needs to be). Of course, maybe we can just make sure each of these boxes has a rounded top as well.

Either way I think it is worth seeing what a rounded top does, if it causes a proper "slide off" effect then we can go with that. Otherwise we might still have to work in some code to help them slide off each other.

So I guess go ahead and give it a try and we will go with it if it works, and just figure out how we integrate this with the hurtbox / frame by frame collision boxes when we get there.

flip40 commented 9 years ago

Been thinking on this, I am willing to bet part of the problem (all of the problem?) is attributed to my still broken physics. I think the "stick" happens due to the player constantly trying to move into the one below him with an increasing Y velocity because he isn't hitting the floor, and thus is "falling". Unity is stopping movement because the vector is inside another collider. I think I need to work on improving that physics interaction would drastically help solve this problem, especially as once we have frame by frame hitboxes this might become more difficult to handle.

I'll work on fiddling with the physics and see if I can't get something that works better than the current version.

ghost commented 9 years ago

What do you think of getting rid of the floor check entirely? Maybe we can have another collider around Sanji's feet to see if it is touching something he can jump off of. Otherwise if the player is at the edge of the floor and touching it on the side somewhere the player can keep jumping

ghost commented 9 years ago

Did you notice how if you get rid of the floor check and one player jumps to a top edge of another player, the jumping player slides down really slowly? And then another strange things seems to happen, at the point where the player jumped from, after the player slides down really slowly and the player runs back to where he jumped from, there is something like an invisible wall

flip40 commented 9 years ago

At your second comment because I type far too much: Yep, I also increased gravity to 10, which seemed to help, but it also lowers the player jump height (we can counter this by changing the jump yvelocity value or something).

Back to what I was typing at the first comment: Hm. I assume you refer to the check in onCollisionEnter. I gave this a try (I left the other two alone for now, seemed fine) and I think it is a step in the right direction. What we need to do though is make sure we only set the yvelocity == 0 if we are standing on something, not just colliding with something (implement this and play around with how collision works when jumping and then hitting the side of the other player, under the right circumstances you stick to his side and don't fall). Know anything about raycasting? I think largely this is the long term solution, so we should look into that. I haven't really checked it out yet, I'll do so on the weekend.

ghost commented 9 years ago

Oh right you mentioned ray casting last time. I haven't tried using it yet but will experiment

flip40 commented 9 years ago

Ok. We should be able to use it to determine if the collider is below us. I don't know the specifics of what information you get from a raycast, but I faintly hope you can determine the actual object your raycast hits, as that would be best.

There is an edge case we want to avoid where we are in the air and hit the player, but the raycast hits the floor and thinks we landed. This would be avoided if (as I hope), they raycast lets us know what object the ray hit. In that case, we can name check to make sure whatever is below us is what we actually collided with before stopping the falling.

ghost commented 9 years ago

Have been kind of slacking on this. Will try and read more into this and try some things before the lec tomorrow

flip40 commented 9 years ago

Ok cool. I did do some research on the raycasting, seems like it will do the trick. You would likely find this page on your own, but I thought its description was quite descriptive so thought I would share it: http://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html

ghost commented 9 years ago

Note: to see a ray cast from Debug.DrawRay() click on Gizmos in game view

ghost commented 9 years ago

I made some changes and the player doesn't get stuck anymore but there's still the issue where the player jumps sort of next to the other player, and the player that jumped would slide really slowly down