Melee Combat: Need advices
by michel saron · in Torque Game Builder · 10/25/2010 (1:19 pm) · 16 replies
Hello,
I check a lot's of thread about melee attack, and I don't find exactly what I need. And I guess there is no perfect way to do that, but multiple ways.
I try to explain what I've done for now:
I have my character and enemies with their animation manager, actor behavior and control. I had an attack animation for the player. But now I need to create something for damage what's in front of the player.
I want to create something generic for damage what's near and in front of the player. But I don't know how to do that. Because for example if there is multiple enemies in front I need to damage all enemies in front not only one specific. And I will probably add this system to enemies because I want that enemies can hurt the player and other characters.
A friend said to me that it's a 2D game so I don't need like in 3D a huge complicate system for collision detection or other stuff like that.
I need your advices, or references for help me to create something simple and effective.
Thanks.
I check a lot's of thread about melee attack, and I don't find exactly what I need. And I guess there is no perfect way to do that, but multiple ways.
I try to explain what I've done for now:
I have my character and enemies with their animation manager, actor behavior and control. I had an attack animation for the player. But now I need to create something for damage what's in front of the player.
I want to create something generic for damage what's near and in front of the player. But I don't know how to do that. Because for example if there is multiple enemies in front I need to damage all enemies in front not only one specific. And I will probably add this system to enemies because I want that enemies can hurt the player and other characters.
A friend said to me that it's a 2D game so I don't need like in 3D a huge complicate system for collision detection or other stuff like that.
I need your advices, or references for help me to create something simple and effective.
Thanks.
About the author
#2
I will keep in touch about what I find.
10/26/2010 (1:12 pm)
Oh yea, sorry, I forgot to say that my game is a side scroller. I don't know what's pickpoint method is exactly, but I will take a look at your link and try to find other stuff about it.I will keep in touch about what I find.
#3
So if it hits and enemy, then your melee attack succeeded, etc.
10/26/2010 (1:29 pm)
pickPoint essentially allows you specify a point (x/y), and some other parameters to filter, and you will get back a list of all object that point hits.So if it hits and enemy, then your melee attack succeeded, etc.
#4
I'm actually a beginner and I don't understand how to you it.
I want to make this pickRect near my player during the attack animation, like using player position (%This.owner.Xposition or something like that), and I don't know how to declare it.
And when it's done how to use the retrieved ID.
Thanks
10/27/2010 (1:16 pm)
Is it possible to you to give me an example please?I'm actually a beginner and I don't understand how to you it.
I want to make this pickRect near my player during the attack animation, like using player position (%This.owner.Xposition or something like that), and I don't know how to declare it.
And when it's done how to use the retrieved ID.
Thanks
#5
Normally, I'd be happy to draw up a nice example for you but I don't have time currently. I'll try to come up with something, but I'm sorry if I can't.
If you're at a very beginner level with TGB, I suggest putting melee off until you're at a point where you have a better understanding of how TGB works. Do some tutorials and build your understanding.
The community is also more willing to help if you post some code that you've tried, so we can make corrections, rather than writing it for you.
10/27/2010 (1:25 pm)
Hi Michel...Normally, I'd be happy to draw up a nice example for you but I don't have time currently. I'll try to come up with something, but I'm sorry if I can't.
If you're at a very beginner level with TGB, I suggest putting melee off until you're at a point where you have a better understanding of how TGB works. Do some tutorials and build your understanding.
The community is also more willing to help if you post some code that you've tried, so we can make corrections, rather than writing it for you.
#6
I will write what I tried when I come back home, because for now I have a strange error like "could not find function PickRect" or something like that. It's not a build error because the game is launched correctly.
Thanks
10/28/2010 (1:12 pm)
Ok I understand.I will write what I tried when I come back home, because for now I have a strange error like "could not find function PickRect" or something like that. It's not a build error because the game is launched correctly.
Thanks
#7
I'm not at a development machine right now and haven't personally used the pickPoint family of methods but I'll do my best to help ya.
First off, I see from the documentation linked that the method is a class method of t2dSceneGraph. So to use any of the methods listed you'll need to do something similar to:
So say we want to write code for an object that "punches" - first we will use pickPoint to grab a point a predefined distance infront of the object.
As I said I'm not at a development machine so I just whipped it up out of my head - so there will probably be errors - but should give you a rough idea of what to do.
gotPunched would be an object method allowing your objects to respond to being punched. "customPunchX" would represent how far in front of the object you want the punch to extend, also "customPunchY" is used to modify where the punch is so vertically.
"customDirection" is added because you want the player to punch in the direction they are facing. It will probably need modifying as I can't remember what coord system TGB uses off hand. So whether - is left or + right will need to be seen.
Just change "customDirection" in the same code that makes the player change direction and you should be golden.
10/31/2010 (7:12 am)
Heya Michel,I'm not at a development machine right now and haven't personally used the pickPoint family of methods but I'll do my best to help ya.
First off, I see from the documentation linked that the method is a class method of t2dSceneGraph. So to use any of the methods listed you'll need to do something similar to:
SceneWindow2D.GetSceneGraph().method(args);
So say we want to write code for an object that "punches" - first we will use pickPoint to grab a point a predefined distance infront of the object.
$CUSTOMDEFINE_FACELEFT = 0;
$CUSTOMDEFINE_FACERIGHT = 1;
function object::punch(%this)
{
// Variable to hold x, y position of "punch"
%startX = %this.position.x;
%x = %this.position.x;
%y = %this.position.y + %this.customPunchY;
// First we figure out what direction the player is facing
if(%this.customDirection == $CUSTOMDEFINE_FACELEFT)
{
%x += %this.customPunchX;
}
else
{
%x -= %this.customPunchX;
}
// Now that we have an x/y position for the punch do the pickLine
%punchList = SceneWindow2D.GetSceneGraph().pickLine(%startX, %y, %x, %y);
// This picks objects between me and punch
// Now we figure out how many objects we hit
%punchCount = getWordCount(%punchList);
if(%punchCount == 0) { return; } // Sanity Check
// Loop through punched items
for(%n = 0; %n < %punchCount; %n++)
{
// Get the object
%obj = %getWord(%punchList, %n);
// Make the object isn't us! - then tell the object that we punched them!
if(%obj != %this) { %obj.gotPunched(%this); }
}
}
function object::gotPunched(%this, %puncher)
{
// Do gotPunched code here
// Decrease health or something probably
// %this = The object being punched (me)
// %puncher = The object that punched me
}As I said I'm not at a development machine so I just whipped it up out of my head - so there will probably be errors - but should give you a rough idea of what to do.
gotPunched would be an object method allowing your objects to respond to being punched. "customPunchX" would represent how far in front of the object you want the punch to extend, also "customPunchY" is used to modify where the punch is so vertically.
"customDirection" is added because you want the player to punch in the direction they are facing. It will probably need modifying as I can't remember what coord system TGB uses off hand. So whether - is left or + right will need to be seen.
Just change "customDirection" in the same code that makes the player change direction and you should be golden.
#8
The only thing I would add to that is to change the callback function to something like:
11/01/2010 (1:02 pm)
Great post Ben!The only thing I would add to that is to change the callback function to something like:
function otherObject::gotPunched(%this, %puncher)
{
// Do gotPunched code here
// Decrease health or something probably
// %this = The object being punched (me)
// %puncher = The object that punched me
}...since you don't want your player punching himself. :)
#9
In the loop ;) . This way we have one base class for both the player and the badies that can punch and be punched.
11/01/2010 (4:57 pm)
Well if you write it that why then the player cannot be punched ;) . Making sure the player doesn't punch themselves is supposed to be handled by:// Make the object isn't us! - then tell the object that we punched them!
if(%obj != %this) { %obj.gotPunched(%this); }In the loop ;) . This way we have one base class for both the player and the badies that can punch and be punched.
#10
Superclass: PunchableGuy
Class: Baddy or Player
Good stuff!
11/01/2010 (7:55 pm)
Ahhh.... very true...Superclass: PunchableGuy
Class: Baddy or Player
Good stuff!
#11
I'll keep in touch about my work regarding what you give to me.
Thanks a lot!
11/01/2010 (9:24 pm)
Hey thanks guyz for your help!! I look forward to try it.I'll keep in touch about my work regarding what you give to me.
Thanks a lot!
#12
It seems to be this line:
%obj = %getWord(%punchList, %n);
When I comment it it's work. Have you got any idea why it's not working because of this line?
11/02/2010 (1:15 pm)
I tried to plug your code into mine and I have an error when I launch the game.It seems to be this line:
%obj = %getWord(%punchList, %n);
When I comment it it's work. Have you got any idea why it's not working because of this line?
#13
11/02/2010 (2:35 pm)
typo....%obj = %getWord(%punchList, %n);should be:
%obj = getWord(%punchList, %n);...as getWord is a function, not a variable as identified by the % prefix.
#15
I changed PictLine for a PictRect.
With Echo function I succeed to have object IDs I catch into my mellee area. But I don't understand what is in my zone. I only have ID (1554 etc...) and I don't know what's objet is really inside (I don't know if I really catch my enemy and not my...background).
I don't know how to retrieve wich object is link to an ID. How I can do that?
And is it possible to check by the name? If my object's name contain "enemyname...' so damage it?
Thanks
11/05/2010 (8:15 pm)
Ok, I plugged it, and it's seems to work.I changed PictLine for a PictRect.
With Echo function I succeed to have object IDs I catch into my mellee area. But I don't understand what is in my zone. I only have ID (1554 etc...) and I don't know what's objet is really inside (I don't know if I really catch my enemy and not my...background).
I don't know how to retrieve wich object is link to an ID. How I can do that?
And is it possible to check by the name? If my object's name contain "enemyname...' so damage it?
Thanks
Torque Owner RollerJesus
Dream. Build. Repeat.
It depends on your game, but for a side scroller that should work fine. If your game has the player rotating, you would need to calculate a point in front of your player at the time of attack.