Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-04-2012, 03:04 PM   #1
Rittto
Registered User
 
Join Date: Aug 2012
Posts: 1
Default [AS2] Character working on a slope

*Posted this on another forum and got no response, so I'm just going to copy paste it here. *

I've actually been looking for a proper way to do this for a really really long time, and I've only come close once.
Basically, I'm trying to make a game with a character that moves upwards/downwards with the angle of the ground he's walking on. (He doesn't have to rotate)

Sounds simple enough. I can't even tell you how many different approaches I've taken. In both AS2 AND AS3.

I'll attach an fla of where I've come close. What I can't figure out is how to make it precise (as in no rumbling while walking up, and no falling when walking down)
A bonus would be: Sliding down if the downward slope is great enough.

Here's the code in P1:
ActionScript Code:
onClipEvent (load) {     var jumping:Boolean = true;     var jump:Number = 0;     var wallleft:Object = {x:350, y:200};     var wallright:Object = {x:375, y:200};     var slideleft:Object = {x:350, y:235};     var slideright:Object = {x:375, y:235};     var catcher:Object = {x:362.5, y:245};     var charpoint:Object = {x:362.5, y:250}; } onClipEvent (enterFrame) {     _root.ground._y += jump;     if (jump<=-10) {         jump = -9;     }     if (_root.ground.hitTest(charpoint.x, charpoint.y, true)) {         jump = 0;         jumping = false;         _root.ground._y -= 5;     } else {         jumping = true;     }     if (_root.ground.hitTest(catcher.x, catcher.y, true)) {         _root.ground._y += 5;     }     if (_root.ground.hitTest(wallleft.x, wallleft.y, true)) {         _root.ground._x -= 5;     } else {         if (_root.ground.hitTest(slideleft.x, slideleft.y, true) && jumping == false) {             if (Key.isDown(Key.LEFT)) {                 _root.ground._y += 5;             }         }     }     if (_root.ground.hitTest(wallright.x, wallright.y, true)) {         _root.ground._x += 5;     } else {         if (_root.ground.hitTest(slideright.x, slideright.y, true) && jumping == false) {             if (Key.isDown(Key.RIGHT)) {                 _root.game.stage._y += 5;             }         }     }     if (_root.roof.hitTest(wallleft.x, wallleft.y, true)) {         jump = -5;     }     if (_root.roof.hitTest(wallright.x, wallright.y, true)) {         jump = -5;     }     if (Key.isDown(Key.SPACE) && jumping == false) {         jumping = true;         jump += 15;     }     if (jumping == true) {         jump -= 1;     }     if (Key.isDown(Key.LEFT)) {         _root.ground._x += 5;     }     if (Key.isDown(Key.RIGHT)) {         _root.ground._x -= 5;     } }

*Then after this, I tried yet another code, which almost worked.*

Okay, I've taken a different approach this time. I found a small tutorial and made some simpler code from that.
It uses a "while" loop, which I honestly have no idea how to use. I had the loop push the character up and it worked perfectly, but I want the character to stay put in the center of the screen, and the stage to move behind the character. When I changed the code, the "while" loop would continue until the character was all the way to the top of the bounding box of the stage.

I'm pretty sure it's because the loop is using the entire bounding box of the stage, but I'm not sure why.

Here's the code:
ActionScript Code:
onClipEvent (load) {     speed = 7;     jumping = false;     jump = 0;     var p1jumppoint:Object = {x:350, y:176}; } onClipEvent (enterFrame) {     if (Key.isDown(Key.RIGHT)) {         _root.ground._x -= speed;     }     if (Key.isDown(Key.LEFT)) {         _root.ground._x += speed;     }     if (Key.isDown(Key.SPACE) && !jumping) {         jump = -12;         jumping = true;     }     if (_root.ground.hitTest(_x, _y, true)) {         _root.test1.gotoAndStop(2);         jumping = false;         jump = 0;     } else {         _root.test1.gotoAndStop(1);     }     if (!_root.ground.hitTest(_x, _y, true)) {         _root.test2.gotoAndStop(2);         jump += 1;         _root.ground._y -= jump;     } else {         _root.test2.gotoAndStop(1);     }     if (jump>=11) {         jump = 10;     }     while (_root.ground.hitTest(_x, _y, true)) {         jumping = false;         _root.ground._y++;     } }

I'll attach an fla with this code in it, since it seems like I almost have it working.
Attached Files
File Type: zip Slope Tester.zip (15.7 KB, 26 views)
Rittto is offline   Reply With Quote
Old 08-04-2012, 05:28 PM   #2
arkitx
Senior Member
 
Join Date: Jan 2011
Posts: 703
Default

http://flashcove.net/268/uneven-terr...ash-games-as3/

http://www.flashgametuts.com/tutoria...in-as2-part-4/


http://www.flashgametuts.com/tutoria...in-as2-part-7/



Visit the above links.


__________________
Regards

arkitx

Last edited by arkitx; 08-04-2012 at 05:31 PM.
arkitx 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


All times are GMT. The time now is 04:02 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.