Pushing back an enemy in a platformer

0 favourites
  • 9 posts
From the Asset Store
Helping streamers give their viewers more excitement.
  • Hello Everyone!

    This is my first post here. As most first posts, mine is a problem I'm having.

    I'm completely new to Contruct 2 and trying to learn what I can from the great tutorials found here and youtube. I'm currently experimenting with a 2d platformer and I'm trying to simulate the player pushing back an enemy. I have it seemingly working in 1 direction, but not in the other. I'd like to apply this effect to more than one enemy in the future, but for now I'd settle on it working on just one!

    The enemy has a platform behavior so it can walk back and forth and fall. It also changes directions when walking into walls with the use of an instance variable. It also has a bullet behavior for the push back effect. I found an example of the effect here: scirra.com/forum/how-to-make-a-simple-sprite-knockback-in-8-dir_topic53242.html

  • For some reason it seems like my post was incomplete. I also added the file to show my problem, but it's not in my post.

    Let's try adding the file again: dl.dropboxusercontent.com/u/98323832/Construct2/PushbackTest.capx

  • What you need to do is whenever you set your enemies direction, also assign it to a variable. For example in my games, when an enemy is moving to the right, I set an instance variable "direction" to "forward". If the enemy is moving to the left I set "direction" to "backward". My event for pushing the enemy should check to see if the direction of the enemy is "forward" or "backward". Then you can adjust it's position accordingly. For example if it is "forward" then to push it back I have to subtract from vector, if it is "backward" then I need to add to vector.

    Hope that makes sense...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • What you need to do is whenever you set your enemies direction, also assign it to a variable. For example in my games, when an enemy is moving to the right, I set an instance variable "direction" to "forward". If the enemy is moving to the left I set "direction" to "backward". My event for pushing the enemy should check to see if the direction of the enemy is "forward" or "backward". Then you can adjust it's position accordingly. For example if it is "forward" then to push it back I have to subtract from vector, if it is "backward" then I need to add to vector.

    Hope that makes sense...

    The enemy in my example file does have an instance variable set up for movement. It's simply called "Dir." It looks like this:

    Enemy > Dir = 0 > Enemy: Simlulate Platform pressing Right

                      Enemy: Set Not Mirrored

    Enemy: Platform has wall to right > Enemy: Set Dir = 1

    Enemy > Dir = 1 > Enemy: Simlulate Platform pressing Left

                      Enemy: Set Mirrored

    Enemy: Platform has wall to left > Enemy: Set Dir = 0

    It seems like the problem I'm having is coming from the player's direction, but I'm not sure. I basically need the enemy "pushed" in the direction the player is facing regardless of what direction the enemy is moving.

  • Then you should have a variable that tracks the players direction and use it instead. You don't need to know the enemies direction in that case, just the players. Use it the same way.

  • Firstly I'd like to thank BluePhaze for trying to help me out. I'm unfortunately not quite grasping the concept and the solution is just eluding me.

    I've done some more searching and a lot more experimenting and found something by xavy027 that's very close to what I was looking for. The thread can be found scirra.com/forum/slide-action-while-keeping-platform-behavior_topic63858.html The solution gave me the push effect that I'm looking for, but it needed a few tweaks. It had a weird bounce back problem when the enemy would hit a wall. I'd rather have it so the enemy would hit the wall and stay stunned for a moment before moving again. I have that almost working, but there seems to be an inconsistency in the push effect.

    If you push the enemy and then push the enemy immediately after it begins moving again, the push doesn't work properly the second time. I'm including the file of the newest example. There's 2 disabled actions that act as timers so you have to wait 4 seconds before using the push again, but even when they're enabled the second immediate push doesn't work right.

    I appreciate anyone taking the time to read this and appreciate any advise even more! Can someone spot what I'm missing or even show me a simpler way to do this?

    Here's my file: dl.dropboxusercontent.com/u/98323832/Construct2/PushbackTest2.capx

  • Hello friends, just wondering if anyone has any insight into my problem? I'd appreciate any and all input!

  • there's a capx in the forums, search Push Pull

  • there's a capx in the forums, search Push Pull

    Thanks for the suggestion but I took a look at the Push/Pull file and I don't think it applies to my problem at all.

    The "push" effect I'm making is more of a forceful push, like a blast of force pushing the enemy back a few feet and then stunning it. If you download the file I provided, you'll see what I mean.

    I'm still hoping for help! <img src="smileys/smiley1.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)