|
-
a simple stick to keep wheels a certain distance apart
I'm working on an artbased platformer game. The player drives a vehicle along the ground.
My problem is that whenever the vehicle climbs a hill, the distance between the wheels spreads apart.
So I tried to research some of the stick and spring models and bike games, but the concept just goes right over my head.
delta = x2-x1;
deltalength = sqrt(delta*delta);
diff = (deltalength-restlength)/deltalength;
x1 += delta*0.5*diff;
x2 -= delta*0.5*diff;
that is directly from the Jakobsen paper that is referred to over and over. I understand what it's doing, but I don't understand where x0 and x1 come from. Are they the actual _x's of the wheels? I've tried applying it in that way, but I'm having odd results. It's causing more problems than it's fixing.
This is the code for _root.wheel2
Code:
dx1=_x-_root.wheel1._x;
dL=Math.sqrt(dx1*dx1);
diff=(dL-rL)/dL;
_x+=dx1*.05*diff;
_root.wheel1._x-=dx1*.05*diff;
dy1=_y-_root.wheel1._y;
dLy=Math.sqrt(dy1*dy1);
diffy=(dLy-rL)/dLy;
_y+=dy1*.05*diffy;
_root.wheel1._y-=dy1*.05*diffy;
I get the feeling I'm doing this totally wrong... Any help would be appreciated.
-
Senior Member
You are using 0.05 in the code, where I think it should be 0.5 or as the idea is to have half of length - 1/2.
You also dont have variable restlength rL declared.
-
Sorry, I should've posted more of the code or explained further.
rL is defined in the load event as rL = 58; (which is the distance apart I want them)
I toyed with changing the .05, and sometimes removing it all together, but that makes the wheels "bounce" opposite eachother when they are on flat ground.
What I am noticing is that whenever the vehicle climbs the hill, this code doesn't actually shorten the distance between the wheels at all... They still spread out really far whether the .05 or .5 is there or not. What I'm thinking is that the "gravity" effects on the wheels might be undermining my attempt to keep them together.
Before I tried this I had my algebra book open trying to find out how to define the wheels' _x and _y by making them conform to a certain diameter, and the center of the circle being the midpoint of the vehicle's body. But I simply couldn't figure out how to apply it.
What I'm thinking is that I might just find the distance between them, and then add or subtract from _x and _y until d <= 58. But I get the feeling that i'll get some messy results...
We'll see.
Thanks
-
Script kiddie
You need to look into Inverse Kinematics (called Inverse Kinetics when dealing with organic stuff). It's used for constraining joints to a certain distance and angle range from a point, and is used for stuff such as ragdoll physics engines.
-
You should go with calculating distance. I cant see how your code would work as it is..
dL=Math.sqrt(dx1*dx1);
is just a slower way of saying:
dL = Math.abs(dx1);
(and I think only needed if your vehicle turns upside down?)
But how can you know if the wheels are too far apart when treating the x and y seperately?
you need a proper distance calculation, ie.
dL=Math.sqrt(dx1*dx1 + dy1*dy1);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|