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.
Quote:
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.