PDA

View Full Version : A couple of questions.



TechedRonan
March 21st, 2006, 09:00 AM
I've got some questions about actionscripting for an upcoming flash project.

1. Is there an more effective way to do hitTests? The square hitbox is just annoying.

2. Physics, easyest way to make em?

3. 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:
_root.casing._x = _root.gun.emitter._x;
_root.casing._y = _root.gun.emitter._y;
Notice: I've tested this, and it's not working.

bombsledder
March 21st, 2006, 09:55 AM
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

TechedRonan
March 21st, 2006, 11:04 AM
Heh, i'm quite far from new in AS. Tough also far from an expert. Still i would consider me a moderate Actionscripter.

For example: the Window duplicator on my homepage is all my work.
Check it our here (http://techedronan.no-ip.info/flash/flash.html)

So far i've actually made a bouncing ball(buggy, but well it's not animated.)

Mostly i would like to know question 3.

optixburn
March 21st, 2006, 07:09 PM
I've got some questions about actionscripting for an upcoming flash project.

1. Is there an more effective way to do hitTests? The square hitbox is just annoying.

2. Physics, easyest way to make em?

3. 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:
_root.casing._x = _root.gun.emitter._x;
_root.casing._y = _root.gun.emitter._y;
Notice: I've tested this, and it's not working.

1. hitTest has 3 different uses (if you don't use flash 8's bitmap hittest)...

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)


2. best physics engine i could find is physics using verlet intergration
article about it here http://www.gamedev.net/reference/programming/features/verlet/

3. 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)

hope this helps

sslaby
March 22nd, 2006, 09:03 PM
I've got some questions about actionscripting for an upcoming flash project.

1. Is there an more effective way to do hitTests? The square hitbox is just annoying.



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 :

x1 =_root.PlayerCar.PCB_1.getBounds(_root).xMin
y1 = _root.PlayerCar.PCB_1.getBounds(_root).yMin
x2 =_root.PlayerCar.PCB_1.getBounds(_root).xMax
y2 = _root.PlayerCar.PCB_1.getBounds(_root).yMax

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.

Hit1 = _root.TrackBounds.hitTest(x1,y1,true)
Hit2 = _root.TrackBounds.hitTest(x1,y2,true)
Hit3 = _root.TrackBounds.hitTest(x2,y1,true)
Hit4 = _root.TrackBounds.hitTest(x2,y2,true)


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.

sslaby
March 22nd, 2006, 09:05 PM
3. 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:
_root.casing._x = _root.gun.emitter._x;
_root.casing._y = _root.gun.emitter._y;
Notice: I've tested this, and it's not working.

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.

TechedRonan
March 25th, 2006, 12:47 PM
I've probably got this wrong.. but anyway:

_root.xPos = _root.something.emitter.getBounds(_root)._x;

Returns "Undefined". Without the getBounds it returns the wrong x Position.

sslaby
March 25th, 2006, 03:48 PM
try :
_root.xPos = _root.something.emitter.getBounds(_root)._xMin

nathan99
March 25th, 2006, 05:23 PM
no.



_root.xPosR = _root.something.emitter.getBounds(_root).xMin
_root.xPosL = _root.something.emitter.getBounds(_root).xMax
_root.yPosT = _root.something.emitter.getBounds(_root).yMin
_root.yPosB = _root.something.emitter.getBounds(_root).yMax

nathan99
March 25th, 2006, 05:27 PM
See also: http://www.kirupa.com/forum/showthread.php?t=204937&highlight=getBounds