Home    LittleBigPlanet 2 - 3 - Vita - Karting    LittleBigPlanet 2    [LBP2] Tutorials
#1

How to make an enemy be knocked back when hit

Archive: 2 posts


I've been working on a top down shooter, and I wanted my enemies to be knocked back when they were hit. I tried using Sequencers and different combinations of things, and nothing worked. But today, I have solved my problem and have decided to share it with all of you in my first tutorial. And post, for that matter.

So I started with a block of cardboard and a Creatinator shooting Plasma Balls. I put a microchip on the box, and added a Gyroscope to keep it upright and an Anti-Gravity Tweaker to make it float. This is just the enemy simulation I used, but it can be incorporated into your enemies as well.

What You Need:

2 Followers, or which ever way you want the enemy to move. Movers and Advanced Movers also work.
1 Selector
1 Timer
1 Sensor


How to set up the logic:

Set the Selector to have 2 Ports, and otherwise leave it at default. Connect each output to a Follower, and Output 1 to the Timer's Reset as well.
Follower 1 is the default, so set that to Follow the Player. If using a Mover, you may want to set it to local space. With an Advanced Mover, you'll also need a battery, or some way to set what direction the enemy is moving.
Follower 2 is the knockback, and is set to Flee Rather than Follow. With a Mover or Advanced Mover, make it set to move inthe opposite direction of the default.
As for the Sensor, Set it to Include Rigid Connections and to Reset When Full, if using a Projectile Sensor. If using hologram for hit detection, you will need to set Include Touching to Yes.
Connect the Sensor to Selector Input 2 and the Timer Input.
Set the Timer input function to Start Playing Forwards. Connect the Timer Output to Selector Input 1.


What the settings do:

Follower 1 can be set to whatever speed you want it to follow the player/tag at. Simple. I used a speed of 4 for my testing.
Follower 2 is how fast the enemy moves back when hit. Higher speeds makes the push look more natural. In my testing, I used 16 for a speed.
The amount of time set in the Timer is how long your enemy will be pushed back for. Lower times make things more natural, since you don't want your enemy moving backwards for too long. 0.2 seconds is a good amount of time.
If you want it to take multiple hits to knock your enemy back, then add in a Counter. Connect the Sensor to the Counter's input, and the Counter's Output goes to Selector Input 2 and it's own Reset. Set the number to however many hits you want it to take.


I have recently found just one problem with how I set this up. The direction the knockback goes is determined by the direction the enemy is facing, not where the projectile comes from. One way around this is to make a holo border for the enemy, one for each direction the projectile can come from. More on this once I have it working.

That's all for now. If there's any improvements that I can make to this, feel free to post. Hopefully, I won't forget about this and will update when need be.
2011-03-10 23:14:00

Author:
SuddenEnigma
Posts: 70


awesome i really need this for this project im doing2011-03-12 00:49:00

Author:
Unknown User


LBPCentral Archive Statistics
Posts: 1077139    Threads: 69970    Members: 9661    Archive-Date: 2019-01-19

Datenschutz
Aus dem Archiv wurden alle persönlichen Daten wie Name, Anschrift, Email etc. - aber auch sämtliche Inhalte wie z.B. persönliche Nachrichten - entfernt.
Die Nutzung dieser Webseite erfolgt ohne Speicherung personenbezogener Daten. Es werden keinerlei Cookies, Logs, 3rd-Party-Plugins etc. verwendet.