Jump to content


Photo

Moving Platforms


  • Please log in to reply
19 replies to this topic

#1 MusicForLife83

MusicForLife83

    GMC Member

  • New Member
  • 9 posts

Posted 01 November 2008 - 01:40 PM

I know, I know, this problem has probably been answered a lot of times on this forum, but everything I find on here doesn't seem to work?

My game is just a simple platform game that I am making for a school assignment, and I have decided to add in moving platforms, the best i can get it is so the character moves the smallest bit when the platfom moves, but other than that, nothing, he just slides off.

I have only been learning game maker for about 2/3 weeks, so I only have a fairly simply, but pretty advanced knowledge of game maker (drag and drop).

But i just cant get this to work, if you want i can upload my game for you to have a look at it, and if you want fix the problem in the file, then send it back to me (which would be greatl appreciated)

or can anyone point me in the direction on how to get this to work?

thanks,

EDIT: http://rapidshare.co...ame4.5.gmk.html

link to download my game

Edited by MusicForLife83, 04 November 2008 - 11:49 AM.

  • 0

#2 Dark Pieman

Dark Pieman

    GMC Member

  • New Member
  • 95 posts

Posted 01 November 2008 - 01:56 PM

"Moving Platforms" are two words I wince at regarding Game Maker. Especially vertical ones. O______O

But, you need to realise that when your guy is standing on a platform with gravity = 0, he isn't colliding with the platform (he's just above it, and not moving towards it - how could he collide?) so don't do anything to the collision event.

With a horizontal platform, use something like

var spd, dir;
dir = instance_place(x,y+1,platform).direction
spd = instance_place(x,y+1,platform).speed
move_contact_solid(dir,spd)

in the step event for when he's standing on a platform, but he will probably still get stuck in some cases.

To help with this, put
move_outside_solid(other.direction,other.speed)

in the collision event with the platform object.

EDIT: changed the code. Still buggy. :-(

Edited by Dark Pieman, 01 November 2008 - 02:12 PM.

  • 0

#3 MusicForLife83

MusicForLife83

    GMC Member

  • New Member
  • 9 posts

Posted 01 November 2008 - 02:14 PM

i dont think the code worked... nothing changed, i think ill upload my game and see if that helps people help me with working it out...
  • 0

#4 MusicForLife83

MusicForLife83

    GMC Member

  • New Member
  • 9 posts

Posted 02 November 2008 - 03:25 AM

im just bumping this because i need it desperatly by tomorrow

any help is greatly appreciated
  • 0

#5 undoingearth

undoingearth

    GMC Member

  • New Member
  • 37 posts

Posted 02 November 2008 - 03:47 AM

make an invisible object
on your plat form add even create
D&d start moving(what ever direction you need)
add event collision on invisible block
reverse hor/vert

then on your character
(if the platform moves up)
add event collision on platform
D&D set vert speed to -3

and that should do it
hope this helps

Edited by undoingearth, 02 November 2008 - 03:48 AM.

  • 0

#6 MusicForLife83

MusicForLife83

    GMC Member

  • New Member
  • 9 posts

Posted 02 November 2008 - 05:06 AM

make an invisible object
on your plat form add even create
D&d start moving(what ever direction you need)
add event collision on invisible block
reverse hor/vert

then on your character
(if the platform moves up)
add event collision on platform
D&D set vert speed to -3

and that should do it
hope this helps


nah it didnt work, can you perhaps download my game and see if you can fix it in there, then send it back to me?

thanks,
  • 0

#7 undoingearth

undoingearth

    GMC Member

  • New Member
  • 37 posts

Posted 02 November 2008 - 05:44 AM

im sry man
i can help
i wish i knew what was wrong but i dont
i like the game though
good job on that
  • 0

#8 Desert Dog

Desert Dog

    GMC Member

  • Retired Staff
  • 6409 posts
  • Version:Unknown

Posted 02 November 2008 - 06:18 AM

Okay, here. I added horizontal platforms. PM me if you want me to add vertical platforms, but I don't have time right now....

http://rapidshare.co...hanged.gmk.html

Hope I've helped!

~DD
  • 0

#9 Botyto

Botyto

    GMC Member

  • GMC Member
  • 1252 posts

Posted 02 November 2008 - 06:29 AM

So.. u want your character to move with the platform, not staying at the same X position?
I haven't done that befour.. but I'll try - I won't test it!

platform create event:
speed=3
platform collision with player:
if (other.y-other.sprite_yoffset)<y+sprite_height
	{
	other.x+=x-xprevious
	}
platform collision with wall:
speed*=-1
btw. that's horizontal moving platform
  • 0

#10 MusicForLife83

MusicForLife83

    GMC Member

  • New Member
  • 9 posts

Posted 02 November 2008 - 07:20 AM

Thanks Desert Dog, it works really well, the one problem I have is having multiple moving platforms in the one room (only one works).
im guessing making each moving platform in a room as a different object might work, but is there a move simple way?
  • 0

#11 lasttea999

lasttea999

    GMC Member

  • GMC Member
  • 290 posts

Posted 02 November 2008 - 07:29 AM

Okay, here's what I did for horizontal platforms, but to use it, you might have to change your other objects. To use this code,
  • You'll have to know how to use arguments in scripts.
  • You'll have to change the name of resources in the scripts to match your own objects.
  • Your character object should probably move to contact position when he hits the platform.
  • Your platform object should be solid.
  • You should use good bounding boxes or masks on all objects.
If you don't understand anything above or below, you should study Game Maker more, in general.

Use this script in the Create event of the platform:

{
	self.dirx = argument0;
	self.spdx = argument1;
}

Use this script in the Step event of the platform:

{
	if (place_free((self.x+self.spdx*self.dirx),self.y)) && !(place_meeting((self.x+self.spdx*self.dirx),self.y,obj_plyrparent))
		{
			self.x += self.spdx*self.dirx;
			if (place_meeting(self.x,(self.y-2),obj_plyr))
				{
					with (obj_plyr)
						{
							self.plat = instance_place(self.x,(self.y+2),obj_mhplat);
							if (place_free((self.x+self.plat.spdx*self.plat.dirx),self.y))
								{
									self.x += self.plat.spdx*self.plat.dirx;
								}
						}
				}
		}
	else
		{
			self.dirx *= -1;
		}
}
Do you understand the scripts?
By the way, this works with multiple platform objects, but not with multiple player objects. You'll have to ask someone else to fix the latter problem... Sorry.

Edited by lasttea999, 02 November 2008 - 07:32 AM.

  • 0

#12 MusicForLife83

MusicForLife83

    GMC Member

  • New Member
  • 9 posts

Posted 02 November 2008 - 10:24 AM

im not really experience with the game maker language, i know html and java script, so i can understand the basics of it
but i have only been using game maker for around 3 weeks, and have only really used drag and drop

i tried doing as you said

i changed some of the names, but i dont really understand the parant thing for the player

anyway, i didnt everything else, i think, correclty, but the character still does not stay on the platform
  • 0

#13 lasttea999

lasttea999

    GMC Member

  • GMC Member
  • 290 posts

Posted 03 November 2008 - 10:33 PM

im not really experience with the game maker language, i know html and java script, so i can understand the basics of it
but i have only been using game maker for around 3 weeks, and have only really used drag and drop

i tried doing as you said

i changed some of the names, but i dont really understand the parant thing for the player

anyway, i didnt everything else, i think, correclty, but the character still does not stay on the platform

Hm. Does this help?
  • Change every instance of "obj_plyr" and "obj_plyrparent" with the name of your character object.
  • Change every instance of "obj_mhplat" (I think there's only one) with the name of your platform object.
  • In the creation event, set both arguments of the initialization script to 1 (just so the movement of the platform can be easily seen).
That should work... When the script does work, it works pretty well.
Also, does your character object move by setting its own speed or by modifying its x position?

Edited by lasttea999, 03 November 2008 - 10:37 PM.

  • 0

#14 Eklund8492

Eklund8492

    GMC Member

  • New Member
  • 109 posts

Posted 03 November 2008 - 10:58 PM

In the moving platforms create event put this code:
hsp = 2

And in it's step event:
if place_free(x+hsp,y){x+=hsp} else {hsp = -hsp}if place_meeting(x+hsp,y,Player) {hsp = -hsp}if place_meeting(x,y-1,Player) {Player.x+=hsp}

Replace 'Player' with your characters object name.
Also check that the moving platform is solid and has got your block object as parent.
The link below leads to an image that shows the 'object form'. Right above where some random guy has circled the sprites mask you can see that it says 'parent' click next to it and choose your block object as a parent.
find the parent

P.S This only creates horizontal moving platforms.

~~Eklund8492

Edited by Eklund8492, 03 November 2008 - 11:11 PM.

  • 0

#15 gogoboy4444

gogoboy4444

    GMC Member

  • New Member
  • 171 posts

Posted 16 August 2009 - 12:06 AM

Well musicforlife, I have done it (I think) if you still need help, here it is

http://rapidshare.co...ame_1_.gmk.html

I also added verticle platforms, and edited the 1st level. sorry if i messed you up :-(
  • 0

#16 Desert Dog

Desert Dog

    GMC Member

  • Retired Staff
  • 6409 posts
  • Version:Unknown

Posted 16 August 2009 - 12:14 AM

Well musicforlife, I have done it (I think) if you still need help, here it is

http://rapidshare.co...ame_1_.gmk.html

I also added verticle platforms, and edited the 1st level. sorry if i messed you up :-(

Errr, that was almost a year ago.....
  • 0

#17 gogoboy4444

gogoboy4444

    GMC Member

  • New Member
  • 171 posts

Posted 17 August 2009 - 12:27 AM

Well musicforlife, I have done it (I think) if you still need help, here it is

http://rapidshare.co...ame_1_.gmk.html

I also added verticle platforms, and edited the 1st level. sorry if i messed you up :-(

Errr, that was almost a year ago.....



WHOOPS :)
  • 0

#18 cpicon92

cpicon92

    MCM Games - mcmco.tk

  • New Member
  • 108 posts

Posted 03 February 2010 - 11:30 PM

I know this topic is over two years old, but it's what comes up first on Google, so it would make sense to have a definitive answer at the bottom.

As things turn out, moving platforms can be done easily enough using a single block of step code (just replace "platform" with the name of the platform object):
if (collision_point(x+16,y+36,platform,false,true)>0) {     x+=instance_nearest(x+16,y+32,platform).hspeed}

if (collision_point(x+16,y+36,platform,false,true)>0) detects if there is a platform under the player (this assumes that the player is 32x32 and its origin is the upper left, if it isn't x+16 would become x+[half your player width] and y+36 would become y+[player height +4]).

If a platform is detected x+=instance_nearest(x+16,y+36,platform).hspeed is run, this will find the horizontal speed of the nearest platform and add it to the current x location of the player. As a result, the player will move with the platform under it.

Note: this is for horizontal platforms would vertical platforms would work the same way, one would just replace "x+=instance_nearest" with "y+=instance_nearest" and "hspeed" would become "vspeed."
  • 0

#19 abramsantana

abramsantana

    GMC Member

  • New Member
  • 1 posts

Posted 09 March 2010 - 11:10 PM

I know this topic is over two years old, but it's what comes up first on Google, so it would make sense to have a definitive answer at the bottom.

As things turn out, moving platforms can be done easily enough using a single block of step code (just replace "platform" with the name of the platform object):

if (collision_point(x+16,y+36,platform,false,true)>0) {     x+=instance_nearest(x+16,y+32,platform).hspeed}

if (collision_point(x+16,y+36,platform,false,true)>0) detects if there is a platform under the player (this assumes that the player is 32x32 and its origin is the upper left, if it isn't x+16 would become x+[half your player width] and y+36 would become y+[player height +4]).

If a platform is detected x+=instance_nearest(x+16,y+36,platform).hspeed is run, this will find the horizontal speed of the nearest platform and add it to the current x location of the player. As a result, the player will move with the platform under it.

Note: this is for horizontal platforms would vertical platforms would work the same way, one would just replace "x+=instance_nearest" with "y+=instance_nearest" and "hspeed" would become "vspeed."


That's awesome thank you!

Though I am still having trouble with it working with vertical platforms, right now my character is continuously bouncing up and down on the platform. Perhaps it has something to do with my characters collision event with the platform. What would you recommend me doing??
  • 0

#20 cpicon92

cpicon92

    MCM Games - mcmco.tk

  • New Member
  • 108 posts

Posted 09 March 2010 - 11:22 PM

Perhaps it has something to do with my characters collision event with the platform.

That seems likely. A lot of this depends on how you do your gravity, do you use the built-in gravity, or do you use your own? If you're using the built-in, is it set to turn off when you're on the platform? Does your platform have another object set as a parent, perhaps one that involves bouncing?

PS: I see that this is your first post here, so welcome.

Edited by cpicon92, 09 March 2010 - 11:23 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users