Results 1 to 2 of 2
-
April 11th, 2012, 07:40 PM #18Registered User
postsSimple HitTest With Rotation and New Direction Problem
EDIT: Check second post!
Hello. I'm having a bit of a problem with my script. I currently have a square that moves across the screen. There is another square on the stage as well. I want the other square to call a hitTest with the first square (that moves), which we'll give an instance of "hero". The hitTest should make the "hero" (or first square) rotation a specific degree (in this case 30) and then move him in a specific direction, either up, or down the y-axis or left or right on the x-axis. This is my current code, attached to my second square.
onClipEvent(enterFrame){
if(this.hitTest(_root.hero)){
_root.hero.rotate += 30;
}
}
The code only says to rotate the hero, but it does not work - any advice? Also, how would I add something like I mentioned above, where the "hero" would also move in a new direction? Any help would be appreciated! The file is attached if any of you have questions on how it might be set up.Last edited by ArcticClaws; April 11th, 2012 at 10:57 PM.
-
April 11th, 2012, 10:53 PM #28Registered User
postsBIG UPDATE!
Okay, so I've gotten the moving square to rotate on a hitTest and to also move on a hitTest. Here is my current code attached to the moving square ("hero").
onClipEvent (load) {
this._y = 100;
this._x = -100;
speed = 2;
}
onClipEvent (enterFrame) {
this._x += speed;
if(this.hitTest(_root.enemy)){
_rotation = 45;
this._y += 2;
}
}
I have one more question though. When I run this, the moving square moves rotates and does move, but only when it hits the other square. Of course this is because of the hitTest. How would I cancel the x-axis movement and only continue the y axis movement? Any help would be appreciated!

Reply With Quote

Bookmarks