All pastes #986425 Raw Edit

Anonym

public text v1 · immutable
·published 2008-04-15 20:04 UTC
rendered paste body
#define MIN_JUMP_HEIGHT                 [1]
#define MAX_JUMP_HEIGHT                 [8]
#define JUMP_HEIGHT                     [2]

static-var jumping, moving, jump_angle1, jump_angle2;

// I'd rather use more than one arg but more than one corrupts stuff apparently
Jump(jump_height)
{
	var jump_speed;

	jumping = TRUE;
	jump_height = get MAX(MIN_JUMP_HEIGHT, jump_height);
	jump_speed  = (get MAX(MIN_JUMP_HEIGHT, get CURRENT_SPEED)) * 4;
	
	move base to y-axis jump_height speed jump_speed;
	turn base to x-axis jump_angle1 speed <120>;
	wait-for-move base along y-axis;
	wait-for-turn base around x-axis;
	
	move base to y-axis 0 speed jump_speed;
	turn base to x-axis jump_angle2 speed <120>;
	wait-for-move base along y-axis;
	wait-for-turn base around x-axis;

	turn base to x-axis 0 speed <90>;
	wait-for-turn base around x-axis;
	jumping = FALSE;
}

AnimationControl()
{
	var height1, height2;
	while (TRUE) {
		if (moving) {
			height1 = get GROUND_HEIGHT((get PIECE_XZ(sensor7))); //front object, part of the root, not the body which holds all the pieces, at y=0, z=16
			height2 = get GROUND_HEIGHT((get PIECE_XZ(sensor8))); //rear object, part of the root, not the body which holds all the pieces, at y=0, z=-16
			// front > rear+[2] => goes up
			if (!jumping AND (height1 > height2 + JUMP_HEIGHT)) {
				jump_angle1 = <-10>; 
				jump_angle2 = <5>; 
				start-script Jump(height1 - height2);
			}
			// front < rear-[2] => goes down
			else if(!jumping AND (height1 < height2 - JUMP_HEIGHT)) {
				jump_angle1 = <5>; 
				jump_angle2 = <-10>; 
				start-script Jump(height1 - height2);
			}
		}
		sleep blah;
	}
}
StartMoving()
{
	moving = TRUE;
}
StopMoving()
{
	moving = FALSE;
}
Create()
{
	moving = FALSE;
	jumping = FALSE;
	start-script AnimationControl();
}