Character speed scaling without choppyness? (Resolved)

Started by poc301, Wed 09/12/2009 17:37:54

Previous topic - Next topic

poc301

I am doing a script for a portion of my new game which requires for an object to pick up speed as it goes...

For instance, character[9] is falling from above, gathering speed as he goes.  When the up-arrow is pressed, the character flaps its wings causing the speed to slow some.  If the up-arrow is pressed enough times he will actually rise back up a short distance and then begin descending again.

The problem is that in order to adjust the speed of the character, I need to stop movement, change speed, and re-start movement.  It looks choppy.

Again, it works fine, has the effect I want, it is just choppy and stuttery, sometimes the speed increases too quickly because the motion isn't fluid and smooth.

Here is the snippet of code I am using, and I would appreciate help (I am using 2.72):



Code: ags


// room script file
int speed=2;  // Speed increment variable
int cspeed=1;  // Scripting variable for changing the player's speed
int up=1; // If up is 1, the falling commences.  If it is not 1, it stops.


#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {

  // script for Room: Repeatedly execute
mouse.Mode = eModePointer;  

lblvelocity.Text = String.Format("%d", cspeed);   // This puts a realtime falling-speed readout on my GUI so I can troubleshoot

while ((IsKeyPressed(372)==0) && up==1) {    // No Up Arrow Keypressed and moving character
	if (speed<30){
  		  speed++;
		  cspeed=speed/2;
		  character[9].StopMoving();
		  character[9].SetWalkSpeed(cspeed,cspeed);
		  character[9].Animate(0, 3, eRepeat, eNoBlock, eForwards);     // So the falling animation continues through the stop/start of the code
		  character[9].Walk(character[9].x, 186, eNoBlock, eAnywhere);
			}
	Wait(1);

	if (character[9].y>180){  // The ground
	if (cspeed>7){
		up=22;
		Display("Too fast");
		character[9].x=160;
		character[9].y = 10;
		up=1;
			}
	if (cspeed<8) {
		up=22;
		Display("Landed Safely");
		character[9].x=160;
		character[9].y = 10;
		up=1;
			}
	}
}




if (IsKeyPressed(372)){    //  Action for flapping of wings


	if (speed<4){
	  up=22;   // Stop falling animation
	  character[9].Walk(character[9].x, character[9].y-15, eBlock, eAnywhere);  // Fly up a few pixels
	  speed=10;  //  Reset to default beginning fall-speed
	  up=1;   // Restart falling script
		}

	if (speed>3){
	speed=speed-3;   // Slow falling speed
	}
	
	if (character[9].y>180){
		if (cspeed>7){
			up=22;
			Display("Too fast");
			character[9].x=160;
			 character[9].y = 10;
		 	up=1;
			}
		if (cspeed<8) {
			up=22;
			Display("Landed Safely");
			character[9].x=160;
			character[9].y = 10;
			up=1;	
			}
}
}
}


Thanks,

Bill

Matti

Sorry, I didn't go through the entire code (partly because you don't use the code tags), but wouldn't it be easier to manually move the character instead of using the .Walk command? Then you wouldn't have to do all the stopmoving-setspeed-walk-stuff.

poc301

Do you mean have the user click and have the character walk?  I can't do that since it is an arcade sequence in the game.  Or do you mean something else?

I didn't use code tags since the entire thing is code lol :)


Thanks,

Bill

discordance

I think he means using character.Move or, even more easily, manually changing the character's y coordinate. That would probably work better than using a walk command.

Matti

Quote from: discordance on Wed 09/12/2009 20:49:08
manually changing the character's y coordinate. That would probably work better than using a walk command.

Yep, that's what I meant.

Quote from: poc301 on Wed 09/12/2009 20:46:27
I didn't use code tags since the entire thing is code lol :)

???

poc301

I will try that, and I modified for code tags :)

-Bill

poc301

#6
Ok, so apparently the character.move command was introduced in 3.1..  I am using 2.72 :(

I got it resolved using the character[9].y movement in the loop.  Looks much better.

Thanks!

-Bill

Khris

For future reference, I'd put all the animations in the character's view and change the loop according to the current x and y movement. (e.g. loop 2 is gliding left, loop 3 is gliding right, loop 4 is falling facing left, etc.)

Then one can focus on getting all the acceleration stuff right without having to worry about animation.
And provided all loops have an equal amount of frames, the different animations will pass into each other nicely.

SMF spam blocked by CleanTalk