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
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
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...
There are a few demo's of using the hitTest method in the demo section of my website complete with source code.....Code:onClipEvent (enterFrame) { if (this.hitTest(_root.someMC)) { this._x += 0; } else { this._x += 3; } }
http://ntdesigns.net
Hope it helps
NTD
A mind once stretched by a new idea never regains its original dimensions.
- Oliver Wendell Holmes
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
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;
}
}
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
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;
}
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
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
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.
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks