Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1

    Default How to make a barrier (wall)

    Hay sup
    ok so i got a circle to move around my screen but nothing i have tried will make it stop when it hits another object it just goes right through it
    so how can i make a solid object that my circle stops at????

    please reply soon thnx

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    You would use the hitTest method to determine collisions.There are several ways to employ the hitTest. To simply check between two movieclips, you can use object code on one of the clips like...

    Code:
    onClipEvent (enterFrame) {
    	if (this.hitTest(_root.someMC)) {
    		this._x += 0;
    	} else {
    		this._x += 3;
    	}
    }
    There are a few demo's of using the hitTest method in the demo section of my website complete with source code.....
    http://ntdesigns.net

    Hope it helps
    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  4. #3

    Default

    thnx but it doesent seem 2 b workin it makes the barrier object move across the screen and then the barrier stops but my man can still go through it

  5. #4

    Default

    hi, um the guy wo explained it first made a little error:

    onClipEvent (enterFrame) {
    if (this.hitTest(_root.someMC)) {
    this._x += 0;
    } else {
    this._x += 3;
    }
    }

    in this case, 'this' has to be the circle, so this also has to be put in the cirles properties, not that of the barrier

    'someMC' is the barrier

    the first x +=0 has to be the opposit of the movement speed. say you have a character who moves to the left with a speed of 5, then the code reades this._x -= 5.

    the second x has to be zero, because this is the alteration of the movement speed when NOT touching the barrier
    so the actual code will be:

    onClipEvent (enterFrame) {
    if (this.hitTest(_root.barrier(or whatever instance name your barrier has)) {
    this._x -= 5;
    } else {
    this._x += 0;
    }
    }

  6. #5
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    There is no error. The code is designed to reside ON the object in motion, not the barrier. Actually, you(aapje) have it backwards. The way you have the code written, if there is a hit detected, the motion of the _x axis is set to -5. If there is no hit detected, you have the motion set to 0... meaning no movement. Here are a couple of hitTest demo's complete with source code for hitTesting an object against multiple barriers, multiple barriers against a single object, and finally an attempt at extending the hitTest method to uniquely sized objects. The last demo was/is experimental and only for testing purposes. The first two demo's would be what to focus on for walls and such...

    http://www.ntdesigns.net/demoFiles/hitTestMC.swf

    http://www.ntdesigns.net/demoFiles/hitTestWalls.swf

    http://www.ntdesigns.net/demoFiles/hitTestProto.swf

    Regards
    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  7. #6

    Default

    hi,
    what i meant with the put it on the object not the barrier thing was that the guy who started the topic (scifi90) put it on the barrier, cos he sais the barrier started moving. My code was suited for a object that you control, and it does not set the end speed, but rather alters it. so if the second x speed (no touching the barrier) = 3, then it would always move 3 harder, until it hits the barrier. if it is 0, the object would go movement speed + 0, rather then movement speed + 3. What I noticed in the demos was that you use a more complicated, though easier to make quick, system:

    speed = 5

    if (Key.isDown(Key.UP)) {
    this.gotoAndStop("up");
    this._y -= speed;
    i on the other hand use a more of a beginners system:
    if (Key.isDown(Key.LEFT)) {
    this._x -= 6;
    }

  8. #7

    Default Help

    Hey ,

    I read what you guys said, and i just got CS3 like 2 days ago. I have learned a great deal, but with the Action Script You 2 provided; It still goes through it, or the wall moves.
    Moving wall:

    onClipEvent (enterFrame) {
    if (this.hitTest(_root.someMC)) {
    this._x += 0;
    } else {
    this._x += 3;
    }
    }

    Non-Moving wall:

    onClipEvent (enterFrame) {
    if (this.hitTest(_root.someMC)) {
    this._x += -5;
    } else {
    this._x += 0;
    }
    }

    Either way i did it, my character wont stop when it gets to the wall.


    Reply please,
    -Jestes

  9. #8
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    Check the help files for how the hitTest method is employed in AS3. Type "hitTest" into the AS panel, highlight it with your mouse and select the help icon(?). It should provide you with how to employ the method along with a code sample.

    Hope it helps
    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  10. #9

    Default Action Script 2.0

    Thanks but i use the action script 2.0 For some reason the 3.0 wont let me make actions. All this is in Cs3. So if that clears anything up. I still couldnt get it to work correctly. But i found a site that may be abl to help me out.
    http://www.actionscript.org/resources/articles
    I looked arround there and found what i was looking for. But they dont explain enough. So it didnt work.

  11. #10

    Default making walls / barriers

    I think this site may have what you're looking for. I found this one to be the easiest to follow:

    http://www.webwasp.co.uk/tutorials/b32-collision-detection/tutorial.php

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. How shall I make the game interesting?
    By flash2004 in forum Site Check
    Replies: 0
    Last Post: 06-12-2006, 05:19 AM
  2. We make quality flash (all what you need)
    By satim in forum Flash Career
    Replies: 0
    Last Post: 06-03-2006, 12:24 PM
  3. What components make up a combobox?
    By silvermoon80 in forum Flash Scripting
    Replies: 1
    Last Post: 11-19-2005, 02:36 PM
  4. Loading Bar? How can I make this?
    By ChitaKatana in forum Newbies
    Replies: 1
    Last Post: 09-24-2005, 03:46 PM
  5. make visible script
    By petard in forum Flash Scripting
    Replies: 3
    Last Post: 12-07-2003, 10:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial