-
hit test movie clip twice??
ok ive got this movieclip "hitbox P2" right now its just on its own in the time line and its just told to move left until it hits the fighter's hurt box so,
Code:
onClipEvent(enterFrame) {
if (attackActive == true )
{
this._x += 500;
}
if(this.hitTest(Object(this._parent).fighter.hurtBoxP1)){
attackActive = false;
}
Capture.PNG
it works fine but the only problem is im using more than one hitbox and thats confusing the hittest alot so it does nothing
so my problem is like is there a line of code that would like let the hit test know its going to be hitting mutiple of the same object or should i just make like 6 new movie clips and have 7 seprate hitboxes
thanks in advance to anyone who responds
-
You cannot use the same instance names for different objects and expect more than one to be targeted. You need to assign unique names, or you can store references to them in an array and use the array to target them.
-
Client Software Programmer
Hello, with a displayList array you can add each hurtBox's string name & check all of the hurtBoxes in a for loop to see if there is something touching:
PHP Code:
onClipEvent(enterFrame) {
if (attackActive == true ){
this._x += 500;
}
var displayList=['hurtBoxP1','hurtBoxP2','hurtBoxP3']
var affectedHealth=[5, 10, 50]
for(var i=0;i<displayList.length;i++){
if(this.hitTest(Object(this._parent).fighter[displayList[i]])){
trace(true)
trace("subtracted " + affectedHealth[i])
attackActive = false;
}
}
}
Last edited by AS3.0; 08-05-2022 at 04:41 PM.
-
Client Software Programmer
Here is an extra example I did to identify the body part affected:
PHP Code:
onClipEvent(enterFrame) {
if (attackActive == true ){
this._x += 500;
}
var displayList=['hurtBoxP1','hurtBoxP2','hurtBoxP3']
var affectedHealth=[5, 10, 50]
var bodyPart=["Head","Body","Legs"]
for(var i=0;i<displayList.length;i++){
if(this.hitTest(Object(this._parent).fighter[displayList[i]])){
trace(true)
trace("subtracted " + affectedHealth[i] + " you were hit from " + bodyPart[i])
attackActive = false;
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|