I’ve got some questions about actionscripting for an upcoming flash project.
Is there an more effective way to do hitTests? The square hitbox is just annoying.
Physics, easyest way to make em?
For guns: How can i make a bullet casing fly out from an emitter inside another movie clip? I also want to be able to rotate the movieclip and still have the emitter following. (I know the code for rotating, basicly i want to know how to make an mc move to a mc inside an mc.)
Ex:[INDENT]_root.casing._x = _root.gun.emitter._x;
_root.casing._y = _root.gun.emitter._y;
[/INDENT]Notice: I’ve tested this, and it’s not working.
you can use an advanced hitTest with the BitmapData class or you could test it by _x and _y, physics? there is no easiest way to make physics, i mean there are good engines but if you make it on your own it might take a you a while since your new to AS, and 3 your gonna need to look up the duplicateMovieClip() and learn about scope in AS
hitTest has 3 different uses (if you don’t use flash 8’s bitmap hittest)… [INDENT]
a. object to object (both with bounding boxes)
b. object to point (point tested against hte bounding box of a the object)
c. object to point (point tested against the shape of the object instad of the bounding box)
[/INDENT]
the rotation problem may require a huge chunk of rotation code that i can’t think of off the top of my head or you might want to try just animation the shell casing in one movie clip and have it’s rotation the same as the gun clip … something like
_root.case._rotation = _root.gun._rotation; (note: you don’t need the rotation of the emitter because that will stay the same inside the movieClip … i assume)
You can basically create dummy objects in your movieclip, and do the hittests on the bounding box of each dummy object against anything they might collide with. I did it for a racing game I made.
It was kind of tricky. I wasn’t aware of how to get the bounding box coordinates of a child object, but here’s how I did it :
PCB_1 is just a dummy object on the player car. I used getBounds to get the bounding box coordinates for the child object. Then I did a hittest on each corner of that dummy object’s bounding box.
It works pretty good. Just 4 hitTests per dummy object though… If you don’t need as much precision or can’t afford as much processing you can just do it on the registration point of each dummy object.
It worked for me, but I didn’t have as many objects to test against, just the trackboundary itself.
if you look in my above post, you can see how I got the boundaries of the child object. That should help you achieve what you are trying to do. Sucks that it doesn’t work like your example code… would be alot easier.