View Full Version : Walking through enemies

05-10-2009, 09:36 AM
I am trying to emulate the enemy damage system found in classic Dizzy games.

What would happen is that when the player is colliding with an enemy, or a dangerous object (such as fire) his energy will go down, however there is no physical reaction... ie he will not bounce back from the enemy or be restricted from moving; he could continue to walk through a large fire, for instance, until all his energy has been depleted (in which case he will die).

I tried messing around with the Spider's (from Treeworld) collision types. If I change it to Warp it performs the desired effect, but unfortunately the spider then stops moving.

Here is my OnDamage() function, which is a modified version of the Treeworld one:

function OnDamage(normal, depth, enemy, damage, userVar, projectile)

if (m_invincibilityTimer != 0) then
if (m_invincibilityTimer > GetApp:GetGameTick()) then
//we can't be hurt yet
m_invincibilityTimer = 0; //not invincible anymore

//GetTextManager:AddCustom(tostring(damage), this, this:GetPos(), Vector2(0, -0.3), Color(200,0,0,255), 2000, C_FONT_DEFAULT);

//GetTextManager:Add("Ouch!", this);
GetSoundManager:Play("audio/player/pain" .. math.random(3) .. ".ogg");

this:GetBrainManager():Add("ColorFlash", "pulse_rate=200;g=-200;b=-200;remove_brain_by_pulses=1");

//make them fall off the ladder if they were on it.

m_hp = m_hp - damage;


05-12-2009, 01:07 AM
So you want the player to be able to walk through enemies but still get hit?

This is easy to do, you have a lot of control over how collision works by setting collision categories.

In ent_spider.lua, if you add:

this:SetCollisionCategory(C_CATEGORY_PLAYER, false);

He won't collide with the player. (In player.lua, the player has defined itself as being in the C_CATEGORY_PLAYER category, and that's why this works.)

Alternatively, you could just do:

this:SetCollisionCategory(C_CATEGORY_ENTITY, false);

in the player's .lua, but if moving platforms or barrels are in the entity category, the player will walk through them. So it just depends on how everything is setup.

Note that SetCollisionListenCategory() works independently of SetCollisionCategory, so you can have things walk through things and not collide, but still 'know' when they collide.

05-12-2009, 09:17 AM
Hi Seth

That's working brilliantly, thanks.
I've used the method suggested with the spider's script because it gives me the flexibility to include other types of enemy that the player can't walk through if I decide I it'd be useful later (I haven't started designing the storyboard/levels of the game yet, I want to get the engine tuned up nicely before getting into the detailed game design).