PDA

View Full Version : Moving platforms and slopes.



elPooter
July 25th, 2004, 03:03 PM
Ok, as everyone might know, I have been working on an art based game for some time now, and I have yet again run into a another problem with the ground. I want to create some moving platforms that go side to side or up and down, and I want the character to be able to walk up and down slopes. My code for the ground goes like this:



onClipEvent (enterFrame) {
if (_root.limits.hitTest(getBounds(_root).xMax, _y, true)) {
this._x -= 2;
}
if (_root.limits.hitTest(getBounds(_root).xMin, _y, true)) {
this._x += 2;
}
if (_root.limits.hitTest(_x, getBounds(_root).yMin, true)) {
this._y += 5;
}
if (_root.limits.hitTest(_x, getBounds(_root).yMax, true)) {
this._y -= 5;
}
}


If any one would like to help, please reply. thanks in advance :thumb:.

-El Pooter.

Mediamonkey
July 30th, 2004, 09:35 AM
how about setting a real limit instead of testing and pushing your character back up?

character._y = Math.max(ground._y, character.currentY);

Now you have set a limit that the character wil never be able to cross, without limiting other free movement. (this is actually just a if/else statement, but looks nicer)

In this example character.currentY is variable (your character jumping around and stuff), ground._y should be pretty constistant, or not, your choice ;)

elPooter
July 31st, 2004, 08:55 PM
oh! Thanx man!