The Daily Click ::. Forums ::. Klik Coding Help ::. All in one
 

Post Reply  Post Oekaki 
 

Posted By Message

W3R3W00F

Drum and Bass Fueled Psycho

Registered
  08/11/2008
Points
  368

VIP MemberCardboard BoxThe Cake is a Lie
3rd July, 2009 at 15:54:35 -

These are a just a bunch of random coding questions I have for creating a short game project I'm working on with a friend. You may answer any of them you like.

First, how would I get a separate object such as a wheel to always set it's position to another object when rotating? (I have no experience with Sin or Cos. )

Second, how would I set a counter's value based on the distance between two points? I'm sure it takes the ADO but I'm not sure what the code would be.

Finally, how would I get the object the wheel is attached to, to rotate when the wheel detects a ramp, hill, or whatever.

Thanks in advance.

 
n/a

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
3rd July, 2009 at 16:43:40 -

Might as well ask for a complete example

1-
Set X of "secondobject" to: X"firstobject"+Round(Cos(Angle)*Distance)
Set Y of "secondobject" to: Y"firstobject"+Round(Sin(Angle)*Distance)
Might have to change one or both + to -

2-Sqr((Abs(X1-X2) pow 2)+(Abs(Y1-Y2) pow 2))

3-Make a basic slope engine with only the back wheel. When it's done, add the second wheel to reposition itself with sin & cos (like in your first question). In your horizontal loop, when the front wheel hits something, rotate your car frame by 1° and reposition the front wheel with that new angle. The car frame's angle & position should depend on the wheels positions and not the oposite, but using it's angle instead of the angle stored to a value is convenient because it turns from 359 to 0 by itself. Then, when only one wheel touches the ground, rotate everything to the ground. That's basicly it.

 
...

W3R3W00F

Drum and Bass Fueled Psycho

Registered
  08/11/2008
Points
  368

VIP MemberCardboard BoxThe Cake is a Lie
3rd July, 2009 at 17:20:17 -

The first two lines of code don't seem to work for some reason. Neither does the code for question 2. Unfortunately I can't make engine either until the code works.

Thanks for helping tho.

 
n/a

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
3rd July, 2009 at 17:42:35 -

It does work. Here's an example:

http://www.mediafire.com/file/0uttnqijyg3/Rotation example (werewoof).mfa

 
...

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
3rd July, 2009 at 19:41:43 -

I presume this is for your side-view racer?
Realistically, you're gonna have to use the Physix extension - no disrespect, but if you can't calculate angles and distances yet, then the maths required otherwise would probably be beyond you (it's certainly waaay beyond my grasp).

Positioning the wheels relative to the car body's center of rotation is quite easy, but it won't help you a lot.

First, you find the X and Y offset of the wheel from the cars center of rotation - ie. the hotspot.
From that, you can find the distance and angle from the center of rotation, to the wheel.
You don't need these events in the game itself - work out the values first, and use them as they are.
Failing that, just guess at the values.

Distance = Sqr(( X_Offset Pow 2 ) + ( Y_Offset Pow 2 ))
Angle_Body_to_Wheel = ATan2( Y_Offset, X_Offset )

Then, in the actual game, you could say:

* Always
-> Set X("Wheel") to X("Body") + (Cos( Angle("Body") + Angle_Body_to_Wheel) * Distance)
-> Set Y("Wheel") to Y("Body") - (Sin( Angle("Body") + Angle_Body_to_Wheel) * Distance)


Here's why I say it won't help you...
Suppose the car is driving along, and the front wheels hit a bump. The front of the car goes up, while the rear stays at the same height. In this case, the center of rotation is at the rear axle.
Suppose the front wheels have cleared the bump, and now the rear wheels hit it. In this case, the center of rotation is at the front axle.
If both wheels go over a bump (or dip) at the same time, the center of rotation is somewhere between the two.

What you really need to do (like Spitznagel says actually), is position the wheels first (using some kind of platform movement), and then set the position and angle of the body to match (angle is the angle from rear wheel to front wheel).
Unfortuantely, this becomes very difficult, as you have to find a way to keep the wheels a fixed distance apart.
Just imagine what would happen if you stopped the car after the front wheels have already gone over the edge of a cliff - either the front wheels would fall off th car, or if you limited their fall somehow then the car would just hang there (instead of being dragged over the edge by the weight at the front of the car.
I've seen a few examples over the years (search clickteam forums), but they've always been buggy as hell - nowhere near good enough to be used in an actual game.

The maths is very complicated - lookup "rigid-body dynamics" on wikipedia - that's basically what you need.
The Physix extension can do this kind of thing, but I've never used it so don't ask me how.

 
n/a

W3R3W00F

Drum and Bass Fueled Psycho

Registered
  08/11/2008
Points
  368

VIP MemberCardboard BoxThe Cake is a Lie
3rd July, 2009 at 22:20:56 -

Spitznagl: Ah, I see. I wrote the code too literally. Thanks.

Sketchy: No, it's not for Project: Nitro, just a small side scroller I'm working on with a friend. I have no experince with the Phizix object either, so that's out of the question. But those are very valid points, so I can see where this will be complicated. Nonetheless, thanks for the tips.





 
n/a

MBK



Registered
  07/06/2007
Points
  1578

VIP Member
4th July, 2009 at 04:59:43 -

I have an idea regarding this if one of you would like to try it. It's for a sideview car or cart with wheels.
Basically, you'd use very little math and no extensions, as is my style (overly complex).. haha!, Here's how it works (it might not):

Cart sits above the wheels as if on shocks.
Always --> set Alt Val A to the difference between Y positions of the wheels. Set animation frame to Alt Val A.
Front wheel is higher than back wheel and the back wheel is lower than front wheel --->
Play the rotate around left (back) wheel animations.
Back wheel is higher than front wheel and front wheel is lower than back wheel --->
Play the rotate around right (front) wheel animations.

Give the wheels some sort of platform movement (both the same)(the cart too) and set the cart frame position to always be centered between the front and back wheel positions.
Don't forget that Gravity must act upon the wheels! and the Cart will follow.

It might not work exactly right, (because of distortion since only using Y of wheels) (although if the cart animations were distorted to fit with it, then it would make for an abstract style) but it'd be interesting to see just how close it comes to being on par with the math method.

(you'll need to create rotation animations of the cart for around both left and right wheels)
It might work, but you'll probably need to make some adjustments as you go.
Anyone care to test it out for me? The math way is probably easier though really, but this way is no extensions for TGF1 IF it works.
It's probably got FAIL written all over it anyway .. lol, but hey, ya never know .. maybe it would work.


 
Click Me! http://www.create-games.com/project.asp?view=main&id=1444

http://www.mediafire.com/download.php?aoo1dnnlq5i

Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
4th July, 2009 at 15:43:54 -

Hmmm. Sounds... interesting.
It would look distorted like you say, but apart from that it might work okay (I'm not about to test it).
It definitely wouldn't be able to handle the cliff edge scenario I described earlier though.

I was thinking maybe do away with the wheels, and use a pair of embedded collision detectors instead. Obviously doesn't allow for moving suspension, but least then you wouldn't have to worry about positioning them properly on the body, or a wheel "falling off".

+ If neither wheel overlaps the ground
-> gravity -> move car down

+ If both wheels overlap the ground
-> move car up (push out of ground)

// reverse events if car is driving right to left

+ If only front wheel overlaps the ground
-> rotate car anti-clockwise

+ If only rear wheel overlaps the ground
-> rotate car clockwise

I think it will be buggy...

 
n/a
   

Post Reply



 



Advertisement

Worth A Click