Getting one actor to rotate around another - gears with teeth

frankwashburnfrankwashburn Member Posts: 32
edited June 2012 in Working with GS (Mac)
Hey all,
So this question was asked before quite some time ago, but I'm running into some problems and I was wondering if anyone had any insight into this.

So I'm trying to make a gear with teeth.

I have the rotating Gear axis, and he just rotates and as he does he contrains an attribute game.gear rotation to his own self rotation.

Then I have 4 teeth so far, each of which:
Constrain X position: (RadiusOfRotation)*cos((game.time+OFFSET)*GearAxisRotationSpeed)+GearAxisX
Constrain Y Position: (RadiusOfRotation)*sin((game.time+OFFSET)*GearAxisRotationSpeed)+GearAxisY

and Constrain Rotation to: Game.gearrotation + ANGLEOFFSET.

ANGLEOFFSET I have down correctly - each of the 4 teeth need to have a different ANGLEOFFSET: 0, 90, 180, 270.

However, the time OFFSET is throwing me off.

QUESTION:
What units are the speed of the "Rotate" rule? Degrees per second?



If so, then what I have been doing is thus:
If the gear axis rotates at 20 degrees per second, then that means that it takes 16 seconds for a full rotation. Then a quarter rotation should be a length of 4 seconds.

That means for GearTooth1, OFFSET should be 4 seconds.
GearTooth2 OFFSET should be 8 seconds
GearTooth3 OFFSET = 12 seconds
GearTooth4 OFFSET = either 0 or 16 seconds.

However, if I do this, then GearTooth1 moves ever-so-slightly not aligned with the proper axis of rotation, GearTooth2 is more misaligned, GearTooth3 even MORE misaligned, and GearTooth4 the most misaligned. There's some problem with the OFFSET value that's throwing them out of whack.

Right now my GearAxis is a square. Instead of each GearTooth coming out of the middle of the side of the square, the first one comes out slightly not-in-the middle and the last one is almost flush with the corner!! It looks awful, and it's clear that there's something slightly wrong with my math. Any ideas?

Answers

  • IsabelleKIsabelleK Member, Sous Chef Posts: 2,807
    You should wait for Joints - without them, the performance will kill your game.
  • frankwashburnfrankwashburn Member Posts: 32
    Fair enough. Is there a listing for upcoming features and their ETA?
  • domeniusdomenius Member Posts: 108
    edited June 2012
    Im guessing you are doing this since you want to be able to dynamically assign a different number of teeth to any given gear? Using that many constrains is going to give you a lot of performance problems. Instead you could create a number of pre-made gear images and just swap them when you want to change the number of teeth, then use the teeth numbers to determine the correct ratio / rotation speed and adjust angular velocity accordingly. Or am I missing the point?
  • frankwashburnfrankwashburn Member Posts: 32
    @domenius Well the problem is that I want the gear axis and the teeth to both be collidable.. Like imagine a giant gear, and you have to navigate your character around/through the spaces between the gear teeth. Considering collision is only "rectangular" or "circular," I don't really see a way to make those spaces between the gear teeth navigable short of making the gear axis and the teeth distinct objects.

    Of course, if this were another engine, I could make a 3D mesh of any shape and assign collision properties according to that specific shape, but yeah, I'm trying to work around Gamesalad's rectangular/circular collision forms.
  • domeniusdomenius Member Posts: 108
    edited June 2012
    Ah, I see. Instead of using relative positioning and a bunch of circle math, you could place rectangular collision volumes at the circles midpoint and then just constrain their rotation to the main circle + an offset. You would only need one collision volume for each set of opposing gear teeth. Of course this would only work if you can live with only using an even number of gear teeth and each tooth is an even length.
  • domeniusdomenius Member Posts: 108
    Actually, don't use a constrain. Just make sure the angular velocity matches between the gears and their teeth volumes and update the initial rotation once on initialization with the correct offset. That should give the same effect and be more efficient.
  • frankwashburnfrankwashburn Member Posts: 32
    @domenius Good lord that is so much simpler. Boy do I feel silly!
  • domeniusdomenius Member Posts: 108
    Glad it worked out :D.

    I wanted to make sure I wasn't lying, so I made a demo project, you probably don't need it but here it is:
    http://www.gamefront.com/files/21823328/teeth.gameproj.zip
Sign In or Register to comment.