Pushing back an enemy in a platformer

Get help using Construct 2

Post » Sun Sep 22, 2013 6:33 pm

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: http://www.scirra.com/forum/how-to-make-a-simple-sprite-knockback-in-8-dir_topic53242.html
B
10
S
1
Posts: 12
Reputation: 476

Post » Sun Sep 22, 2013 9:00 pm

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: https://dl.dropboxusercontent.com/u/98323832/Construct2/PushbackTest.capx
B
10
S
1
Posts: 12
Reputation: 476

Post » Mon Sep 23, 2013 2:39 am

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...
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,603

Post » Mon Sep 23, 2013 3:16 am

[QUOTE=BluePhaze] 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...[/QUOTE]

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.

B
10
S
1
Posts: 12
Reputation: 476

Post » Mon Sep 23, 2013 4:42 am

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.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,603

Post » Tue Sep 24, 2013 3:14 am

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 http://www.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: https://dl.dropboxusercontent.com/u/98323832/Construct2/PushbackTest2.capxMcflygold2013-09-24 03:16:51
B
10
S
1
Posts: 12
Reputation: 476

Post » Tue Sep 24, 2013 8:28 pm

Hello friends, just wondering if anyone has any insight into my problem? I'd appreciate any and all input!
B
10
S
1
Posts: 12
Reputation: 476

Post » Wed Sep 25, 2013 1:31 am

there's a capx in the forums, search Push Pull
B
12
S
3
G
1
Posts: 347
Reputation: 2,866

Post » Wed Sep 25, 2013 2:14 am

[QUOTE=ghost] there's a capx in the forums, search Push Pull
[/QUOTE]

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!
B
10
S
1
Posts: 12
Reputation: 476


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], MadSpy and 8 guests