The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 2 of 2

Thread: Simple HitTest With Rotation and New Direction Problem

  1. #1

    Simple 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.
    Attached Files Attached Files
    Last edited by ArcticClaws; April 11th, 2012 at 10:57 PM.

  2. #2
    BIG 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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012