Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-10-2007, 03:50 PM   #1
tim281080
Member
 
Join Date: Jan 2006
Posts: 57
Default character landing on a moving platform, and stay with it?

Hi There,

Im creating a small platform game but i dont know how to get my character to land and stick to the platforms that fly by.

I have made the platform come from the right and move to the left and my character to can jump by i dont know how to code the hittest so that when he lands on the platform he stays on there and stays at the same rate aws the platform.

my heros actions script is this...

Code:
onClipEvent (load) {
	
	characterSpeed = 3; 
	
//Where the character start jumping from
y_start = _y; 
//On load, jumping is false
jumping = false; 
//And jumpspeed is 0
jumpspeed = 0;
}

onClipEvent (enterFrame) {
//If jumping is true
if (jumping) { 
//The _y + jumpspeed = _y
_y += jumpspeed; 
//And here is the gravity which makes the character fall
jumpspeed += .8; 
//But if the characters's _Y > than the y_start
if (_y>=y_start) {
// The characters's Y = y_start
_y = y_start; 
//And jumping is false
jumping = false; 
} 
} 
//Else
else { 
//If the SPACE Key is down
if (Key.isDown(Key.UP)) {
//Jumping becomes true
jumping = true; 
//And jumpspeed is -14
jumpspeed = -10; 
// playjumping animation
this.gotoAndPlay("jump");
} else {
	if (Key.isDown(Key.DOWN)) {
		this.gotoAndPlay("crouch");
	}
}
}

if (Key.isDown(Key.RIGHT)) { 

this._x += characterSpeed; 
} else if (Key.isDown(Key.LEFT)) { 

this._x -= characterSpeed; 

} 
}

and here is the code on the platform...

Code:
onClipEvent (load) {
	moveSpeed = -5;
	this._x = 550;
	this._y = 245;
}

onClipEvent (enterFrame) {
	this._x += moveSpeed;
	
	//if this goes off the edge of the screen, move back to the start
	if (this._x <=-100) {
		this._x =550
	}
}
Any help would be amazingly appreciated. Thankyou

Tim
tim281080 is offline   Reply With Quote
Old 08-12-2007, 08:26 AM   #2
wyat
Registered User
 
Join Date: Jul 2006
Posts: 13
Default

At the end of the enterFrame sequence for your character, you can try following this pseudocode.


if character is on a platform
{
xRideSpeed = platform's speed;
}else{
xRideSpeed = 0;
}
this._x += xRideSpeed;
wyat is offline   Reply With Quote
Old 08-13-2007, 09:25 AM   #3
tim281080
Member
 
Join Date: Jan 2006
Posts: 57
Default

ahhhhh... Thanks for that Wyat,

So whats the collison detection for getting him to land on the platforms?

Tim
tim281080 is offline   Reply With Quote
Old 08-18-2007, 01:14 AM   #4
wyat
Registered User
 
Join Date: Jul 2006
Posts: 13
Default

Instead of the boolean variable 'jumping', you can use a string variable so you have, say, current_state = "falling","jumping", or "standing".


There are several ways to land on platforms; two of them are below.

Quick and dirty method:
when falling,
Use hitTest and see if your character hits the platform and change current_state accordingly, something like current_state = "standing".

Cleaner method:
when falling,
1. check the distance between character and platform and see if platform is below character.
2. check if the character's x is between the platform's rightmost x and leftmost x position.

3. If condition 1 and 2 is true, then test character's falling increment for the next frame. If this increment is greater than the distance between character and platform (the value obtained in step 1), then readjust the fall increment to the value in step 1.
wyat is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS1] movie clips wont stay static on platform game impsvi Gaming and Game Development 0 04-13-2006 12:46 PM
[AS2] Platform codes - game Danny green Gaming and Game Development 2 02-22-2006 07:22 PM


All times are GMT. The time now is 04:21 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.