Announcement

Collapse
No announcement yet.

Enemy/obstacle collision 2D

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Enemy/obstacle collision 2D

    Hello,

    I'm creating a 2D platformer where the goal is to kill enemies by jumping on their head (I know, not original lol). Anyway, my enemies are created, they're walking around in my level. Now what rests is the collisions with my enemies.

    ![alt text][1]


    Click image for larger version

Name:	examplespriteflipbook.png
Views:	1
Size:	12.5 KB
ID:	1137325
    (this is not how the actual flipbooks look)

    I want to create a collision where, if I touch him from the front or back (red area) it damages me, and if I jump on the top (green area) I kill it.

    Any suggestions would be greatle appreciated!

    #2
    it comes down to how precise your stomping needs to be. If you don't really need pixel perfect stomping, then placing some collision box would be the way to go.
    So it comes to the idea of hit box and hurt box like in fighting games. your character will have hurt box all around and only have hit box around it's feet, on the other hand, your enemy character will have hit box all around and only hurt box on its head area. so the only viable way for your character to stomp properly will be approaching from top of enemy, because otherwise your hurt box will over lap enemies' hit box first.

    But if you need pixel perfect stomping, you might need to develop some custom collision shape or fancy collision detection in order to avoid some traditional glitches that are present in almost all stomping games.
    However, I don't think that's really necessary, since if you place your boxes properly, it wouldn't really affect gameplay at all.
    Unreal Engine 4 Game Framework diagram for relation of all major base object types
    Unreal Engine 4 Input Event diagram, scroll down to section Input Processing Procedural
    Resident Evil Classic Camera
    RPCs official document, Must Read
    Everything you should know about replication

    Comment


      #3
      No I don't need pixel perfect stomping. I just need a collision where if the character jumps on the head, they die/get hurt. However if they touch me, I lose a life. I've tried and tried, examples, tutorials etc. I just can't seem to get it to work.

      Comment


        #4
        Anyone any ideas?

        Comment


          #5
          Originally posted by Penhoat View Post
          Anyone any ideas?
          Hi Penhoat,

          The way the original Super Mario Bros. handled it actually had nothing to do with the head, and only depended on the player velocity. If Mario was falling when he touched an enemy, then that was a 'stomp', but if Mario was level or raising (jumping up) then it counted as a 'bad touch' and he lost a life or his superpower.

          This is pretty easy to implement, just define the collision shape for your enemies, and in the collision response, look at the player's Z velocity. If it is less than 0 then stomp the enemy, otherwise if it's >= 0 then the hero is jumping or standing and should take damage.

          Cheers,
          Michael Noland

          Comment


            #6
            Originally posted by Michael Noland View Post
            Hi Penhoat,

            The way the original Super Mario Bros. handled it actually had nothing to do with the head, and only depended on the player velocity. If Mario was falling when he touched an enemy, then that was a 'stomp', but if Mario was level or raising (jumping up) then it counted as a 'bad touch' and he lost a life or his superpower.

            This is pretty easy to implement, just define the collision shape for your enemies, and in the collision response, look at the player's Z velocity. If it is less than 0 then stomp the enemy, otherwise if it's >= 0 then the hero is jumping or standing and should take damage.

            Cheers,
            Michael Noland
            Ha, Mickaek everywhere to bring help on 2D Developer , anyway as Michael said you can based on Velocity simple, and Also check the Current X position of the Player depending on what you expect !

            Comment


              #7
              Originally posted by Michael Noland View Post
              Hi Penhoat,

              The way the original Super Mario Bros. handled it actually had nothing to do with the head, and only depended on the player velocity. If Mario was falling when he touched an enemy, then that was a 'stomp', but if Mario was level or raising (jumping up) then it counted as a 'bad touch' and he lost a life or his superpower.

              This is pretty easy to implement, just define the collision shape for your enemies, and in the collision response, look at the player's Z velocity. If it is less than 0 then stomp the enemy, otherwise if it's >= 0 then the hero is jumping or standing and should take damage.

              Cheers,
              Michael Noland
              Hello, I'm sorry with the late response to your solution. Your solution sounds amazing and great, yet I have no idea how to make a blueprint like that, could you give me some help with it?

              Comment


                #8
                You could have the Hit event of the player trace downward for the enemy and kill said enemy if the trace returns an enemy. If it doesn't hit, it could trace in any other direction (up, left, right) for the enemy and hurt the player if any of those return true.
                DO contact me with questions about Blueprint or other Unreal features! I don't bite! Or charge money! Just press that blue Skype button and fire away.

                Project Culverin - Open Ended First Person Shooter

                Comment


                  #9
                  All these solutions sound amazing, the thing is, I'd like to know how to actually make the blueprint for that. If anyone could help me with that?

                  Comment


                    #10
                    Click image for larger version

Name:	BPScreenCap.png
Views:	1
Size:	318.1 KB
ID:	1053884

                    This is untested, but this should be pretty close to what you're looking for.

                    EDIT: To clarify, this code should exist within the player character. This is assuming that you want attacks to be instant death, and that all enemies are subclases of "pawn". These particular things might change depending on how you've coded your game.
                    Last edited by Ray Jones 312; 08-24-2014, 03:20 PM.
                    DO contact me with questions about Blueprint or other Unreal features! I don't bite! Or charge money! Just press that blue Skype button and fire away.

                    Project Culverin - Open Ended First Person Shooter

                    Comment


                      #11
                      Compiling it works, however for it to work I'd need my "enemies" to work as well

                      Comment


                        #12
                        Originally posted by Penhoat View Post
                        Compiling it works, however for it to work I'd need my "enemies" to work as well
                        What's wrong with the enemies?
                        DO contact me with questions about Blueprint or other Unreal features! I don't bite! Or charge money! Just press that blue Skype button and fire away.

                        Project Culverin - Open Ended First Person Shooter

                        Comment


                          #13
                          Originally posted by Ray Jones 312 View Post
                          What's wrong with the enemies?
                          These are my blueprint and component of my "enemy"
                          Click image for larger version

Name:	graph1.png
Views:	1
Size:	454.1 KB
ID:	1053929
                          Click image for larger version

Name:	graph2.png
Views:	1
Size:	103.6 KB
ID:	1053930

                          It has no effect on him whatsoever

                          Comment


                            #14
                            I have an idea. I'm at work so I don't want to drill into what Ray posted at the moment. But another idea that might work for you, especially if you're going to make a lot of enemies is this:

                            You can set up trigger volumes (which would be like a hit box) on the enemies head. When the character overlaps that trigger volume then you can destroy the actor (your enemy) (you may need to play a death animation > then destroy actor for immersion). I've also not tested this but it could be as simple as this:



                            Now, you'd want a specific box. See how it says "Trigger box copy" ? That's because I made a trigger volume, named it trigger box (made a copy for this thread), and when my character walks through it the game will spawn an enemy. Instead of the game spawning an enemy, your game will destroy the actor. There are other options besides overlap, like hit, if you want a collision and not to just pass through it.

                            In the image above you'd place that in your character blueprint. As long as you only ever used your "kill box" (whatever you name your trigger volume) on enemies, then whenever the character/player overlaps with that box that enemy (actor) is going to die (be destroyed). You don't want to use that box on other instances or things, because you might accidentally destroy whatever instance of whatever you applied it to if your character triggers that function (don't put that same trigger volume on a platform or something, if your character landed on the kill box he'd destroy the platform and you'd fall down into nothingness or a kill box or whatever).

                            The target "other actor" feeds into the "destroy actor" because you want the OTHER actor (not your character) to be destroyed.

                            I can give this a test run later when I'm out of work.

                            edit; for quick testing you can use an "attach to" function to attach the trigger volume to a socket on your enemies head (You'd have to look at the skeleton and make a socket in the right spot). If you're not sure how you'd get the trigger volume on your enemies head this a quick way to test it.
                            Last edited by zlspradlin; 08-25-2014, 12:31 PM.

                            Comment


                              #15
                              Originally posted by Penhoat View Post
                              These are my blueprint and component of my "enemy"
                              [ATTACH=CONFIG]9747[/ATTACH]
                              [ATTACH=CONFIG]9748[/ATTACH]

                              It has no effect on him whatsoever
                              A couple possibilities here:
                              Your enemy sprite may not be blocking the visibility channel, and
                              Your enemy may not be a subclass of pawn. You will need to change the class defined in the "Class is child of" node in the player code to whatever the parent class of your enemy is.
                              EDIT: Also, turn on the debug (set the little drop down on the single line trace node to "persistent") for the line trace and take a screenshot after you hit something. I may have just done the math wrong with those vectors!
                              Last edited by Ray Jones 312; 08-25-2014, 01:13 PM.
                              DO contact me with questions about Blueprint or other Unreal features! I don't bite! Or charge money! Just press that blue Skype button and fire away.

                              Project Culverin - Open Ended First Person Shooter

                              Comment

                              Working...
                              X