Melee attacks?

I’ve always wondered HOW to do this, but I never asked… until now.
I decided to take a crack at it, and everything was going well, but here’s my problem—
The setup:

I placed an empty in front of my player and gave it a ray, when combined with LMB, the enemy takes damage (by message) and he dies.
This worked fine, until I duplicated the enemy and now if one of em dies, THEY BOTH DIE!!

Is there a better solution?! This method isn’t too great…

You need Python to identify which enemy was hit, and then to interact with him in particular. Also, you should probably use an object that can be collided with rather than a ray, so that you have more possibilities to hit objects.

Your duplicated enemy is sharing a material. The ray is reacting to the material and ending every object that owns that material. You have to manually add a new material to each individual enemy.

The way I do melee attacks is extremely simplistic, but effective. I have an invisible object get added in when the attack happens, and it has a life span of only a few ticks. I then make it so that if the enemy object touches this melee object (and not when the melee object touches the enemy, HUGE difference), the damage is applied.

Keyboard “attack button”---------------and------------------edit add object (invisible static ghost cube-Property:“PlayerHit”,1 frame)
Property"timer"=0-------------------------/ ------------------------set timer = 1

interval timer min:1 max (attack animation length -1)—and------------add 1 to timer

property timer = (end frame of animation)-----------------and------------timer = 0

if timer changes -------------------------------------------------and------------play action based on property timer

this does a few nice things,
you can’t “mash” attack and interrupt the attack animation, it controls the animation, and adds the invisable static ghost “collision flag”

in the dragon

collision with property “PlayerHit”--------------and---------------“health add -5”
Property"timer"=0-----------------------------------/ ------------------------set timer = 1
interval timer min:1 max: (take damage animation length -1)—and------------add 1 to timer
property timer = (end frame of animation)-----------------and------------timer = 0
if timer changes -------------------------------------------------and------------play action based on property timer

(again play animation and take damage resetting to take damage again)

Note that the “start and end frames” can be any, you just need to adjust the numbers accordingly.

This all depends on your logic.

It sounds like you let the “weapon” spread damage through the scene. But I do not know how you do this. Obviously you are dealing with all “enemies” rather than just the hit one.

As SolarLune suggested you can use Python to deal with the involved objects only. You can do that by letting the “weapon” detect where it made damage and notify the involved objects directly (e.g. via property).

An alternative is to let the “enemy” detect the received damage. This way you do not need python, but you need to replicate the damage logic for all objects that can be hit.

With both methods the damaged object can deal with the damage itself or a separate damage handler can calculate the “effective” damage (e.g. after calculating strength, duration, armory etc.).

here is something nifty


you may use it directly if you want


HitDFX.blend (557 KB)

Best way of fixing your problem is by using python, as Monster and SolarLune have mentioned.

Piece of Advice:
Don’t use messages to send information to a specific object. Always address the object in question directly.
Messages should only be used, in my opinion, when you want to broadcast an action to a list of objects that is constantly changing.
I really never find a reason to use messages, because most of them time you can address any, and all, objects you need directly without having to send out a message. In other words, if you keep track of all the objects in your scene(s), I don’t think you’d need messages (unless you’re only on logic bricks that is).

How I did it:
The malee weapon has an empty attached to it that generates a cube (invisible, ghost, actor) everytime you press on your attack butten.
The cube is parented to the empty wich in turn is parented to the bone that moves the weapon.
The enemy has a “Near” sensor on its physics collision box set to detect the property of the cube at a distance of “1.0” (basically touching it).
If you have multiple attack moves or multiple weapons you can have the bones (the ones that cycle through the states as you go from attack to attack) send messages to the empty or empties to create certain cubes (that do more or less damage).

Seems like the majority went with cubes being spawned in,
I wont mark this thread as answered now because I’m bound to fail epically.

Thank you EVERYONE for your answers, the only thing I’m worried about is the wall.collision script picking up the cube…

That depends… is the script there to detect ALL objects or ust the players?
I’d give all the characters the property of “game character” and let that be detected, so other things wont cause problems…

Ah, what I meant was a camera collision, and I’m not too familiar with python.
I’m sure it’s only 1 or 2 lines of text though, it’d be VERY helpful cause now the camera gets ridiculously close to the player when you’re next to a chest, or a damn fence. (wooden fence too!! It’s not even tall)

I was thinking of having a property called “Wall” because there’s only a few things I want to collide with the camera.
I had to make the sword -no collision- because the camera would keep hitting it…

Oh wow, I love the effect. That’s what my game’s missing.
It’s cartoony as hell, but no effects.

IF I do end up using it, I’ll give credit to where it’s owed :]

I dont know much of python either, but have the cam react on a property instead of EVERYTHING is of course a lot better XD
Also, both the character itself and the sword should be no-collision.
Physics should be handled by invisible cubes (like the cube that appears when you make attack moves)