DriveWheel, Z-Axis Rotation

Subscribe to DriveWheel, Z-Axis Rotation 8 posts, 4 voices

Sign in to reply

 
avatar for Mond Mond 82 posts
I have an 18 pixel diameter DriveWheel in my game I want to rotate about the Z-axis when my weapon moves along a specific path. Here are some values I traced out:

Velocity:16.500034468101305
dt:33
previousAP:7784 currentAP:7791
----------------------------------
Velocity:20.100034468101306
dt:36
previousAP:7791 currentAP:7798
----------------------------------
Velocity:23.600034468101306
dt:35
previousAP:7798 currentAP:7805
----------------------------------
Velocity:27.000034468101305
dt:34
previousAP:7805 currentAP:7812
----------------------------------
Velocity:30.300034468101305
dt:33
previousAP:7812 currentAP:7819
----------------------------------
Velocity:33.600034468101306
dt:33
previousAP:7819 currentAP:7826
----------------------------------
Velocity:36.9000344681013
dt:33
previousAP:7826 currentAP:7833
----------------------------------
Velocity:40.4000344681013
dt:35
previousAP:7833 currentAP:7840
----------------------------------
Velocity:43.8000344681013
dt:34
previousAP:7840 currentAP:7847
----------------------------------
Velocity:47.1000344681013
dt:33
previousAP:7847 currentAP:7861
----------------------------------
Velocity:50.400034468101296
dt:33
previousAP:7861 currentAP:7875
----------------------------------
Velocity:53.70003446810129
dt:33
previousAP:7875 currentAP:7889
----------------------------------
Velocity:57.800034468101295
dt:41
previousAP:7889 currentAP:7903
----------------------------------
Velocity:61.20003446810129
dt:34
previousAP:7903 currentAP:7917
----------------------------------
Velocity:64.50003446810129
dt:33
previousAP:7917 currentAP:7931
----------------------------------
Velocity:67.80003446810129
dt:33
previousAP:7931 currentAP:7945
----------------------------------
Velocity:71.50003446810129
dt:37
previousAP:7945 currentAP:7966
----------------------------------
Velocity:75.00003446810129
dt:35
previousAP:7966 currentAP:7987
----------------------------------
Velocity:78.30003446810129
dt:33
previousAP:7987 currentAP:8008
----------------------------------
Velocity:81.60003446810128
dt:33
previousAP:8008 currentAP:8029
----------------------------------
Velocity:84.90003446810128
dt:33
previousAP:8029 currentAP:8050
----------------------------------
Velocity:88.20003446810128
dt:33
previousAP:8050 currentAP:8071
----------------------------------
Velocity:91.50003446810128
dt:33
previousAP:8071 currentAP:8092
----------------------------------
Velocity:94.90003446810128
dt:34
previousAP:8092 currentAP:8113
----------------------------------
Velocity:98.50003446810128
dt:36
previousAP:8113 currentAP:8141
----------------------------------
Velocity:102.20003446810128
dt:37
previousAP:8141 currentAP:8169


The AP values are Array Pointer values. The AP values control the weapon's movement. There is approximately one pixel of movement for each element in the array. That is to say, going from AP=110 to AP=111, the weapon has moved one pixel along it's parabolic path.

The weapon can accelerate to a maxVelocity, which is dependent on the level of upgrade for the weapon. At the higher velocities any detail in the DriveWheel becomes a blur. So it just has to look good in the lower velocities.

I think I have to use the velocity to determine the DriveWheel frame number to display gotoAndStop(DetermineDWFrameNumber()); I could use the AP differential, but the AP value rolls over from 11368 back to 0. So the differential isn't always consistent in a "previousAP minus currentAP" kind of way. If the velocity is negative, the DriveWheel has to reverse direction since the weapon reverses direction along it's path.

This will probably end up being a "trial and error" sort of thing, but could anyone suggest an equation/algorithm to help me get this started? Also, how many frames should the DriveWheel MC have in it? 20? 50? 360? I used 360 frames in my weapon MC and it still looks a little bit steppy to me. Thanks for any help.
 
avatar for Phantasmagoria Phantasmagoria 395 posts

Why does this AP thingy loop if it represents a point on a parabolic path? Does your weapon teleport from one end of the path to the other?

Any reason you can’t just rotate the movieclip instead of making separate frames for a rotation animation?

And why do you need a big complicated array for the path, anyway?

As for what you asked… unless I’m missing something, it ought to be really simple. Something like this:

rotation = ((velocity * constant) + rotation) % maxrotation
 
avatar for Mond Mond 82 posts

Hi Phant. The path the weapon travels is a closed loop.

I don’t understand the “just rotate the movieclip”, don’t I have to use an animation to get Z-axis rotation on an object? I don’t know any other way of doing it.

The larger the array, the more detailed & smooth the movement.

I was thinking more in terms of one pixel of movement along the path should equate to one pixel of movement along the circumference of the drive wheel. I’m working in AS3.

 
avatar for Mond Mond 82 posts

OK. I found the Matrix Class and Transform Class (reminds me of OpenGL) and rotate method.

Isn’t the MovieClip and its frame numbers analogous to an array and its index? If array access is the fastest access possible, it seems reasonable that frame number access would also be the fastest access. The vector graphics data would have been pre-transformed before storing it in its frame number location. Or is it just the base vector graphics that is stored (frame 1 for instance), and each frame number location actually refers to a set of transformation matrices that are needed to represent the graphics for that frame? The transformations (Dot Products or Cross Products) still have to occur to render to the screen, therefore no time is saved by using the animation Z-axis rotation method?

 
avatar for Phantasmagoria Phantasmagoria 395 posts

A parabolic path can’t be a closed loop. What’s the shape of the loop?

Erm, you don’t need all those fancy transform classes for simple rotation. Just set the rotation property of the movieclip (or shape or whatever it is).

I hear array access is actually pretty slow in Actionscript. I haven’t tested it myself, though.

Setting up hundreds of prerendered rotated animation frames can be done, and it might even be faster (or it might be slower!), but you shouldn’t worry about something that complex until you already have your game running. And even then only worry about it if profiling shows that that particular thing must be sped up, and you’ve already tried everything simpler. Seriously, you’ll get nowhere fast if you insist on doing such complicated things for the sake of speed before you even know if you need more speed or if it will help.

 
avatar for Jabor Jabor 4360 posts

Optimization is something you should put off, indefinitely if possible. Just write your code so that the optimization is only changing code in one place, and then you can come back and do it if you find it necessary.

 
avatar for Mond Mond 82 posts

The path is parabolic in some sections, circular in others, linear in others.

I will be using the rotate method on these drive wheels, I just didn’t know the rotate method existed.

As far as the rest of what I posted (MC vs array), I was just thinking out loud. Thanks for the help.

 
avatar for FunkyPear FunkyPear 135 posts

Edit: Nevermind

Sign in to reply