Jump to content

Need help with Flash platformer game

Go to solution Solved by RelentlessAF,

And where do I add the code? I'm sorry, I'm pretty much a code illiterate :/

I don't really understand the code for this myself, but you could have a collision function that makes the character follow the platform on the X Axis when it's colliding with it.

So for school, I have to create a flash platformer game about recycling. Everything seems to be working fine except for one thing. As I was designing my fourth level, I decided to create moving ground, but when the character lands on the moving ground, he doesn't move with it, but stays in place then plummets to his death. Here's a video to explain what I mean:

 

(problem is shown towards the end of the video)

 

I'm using action script 2 and this is the character code:

 

onClipEvent (load) {var ground:MovieClip = _root.ground;var grav:Number = 0;var gravity:Number = 2;var speed:Number = 12;var maxJump:Number = -24;var touchingGround:Boolean = false;}onClipEvent (enterFrame) {_y += grav;grav += gravity;while (ground.hitTest(_x, _y, true)){_y -= gravity;grav = 0;}if (ground.hitTest(_x, _y + 5, true)){touchingGround = true;}else{touchingGround = false;}if (Key.isDown(Key.RIGHT)){_x += speed;_xscale = 100;}if (Key.isDown(Key.LEFT)){_x -= speed;_xscale = -100;}if (Key.isDown(Key.UP) && touchingGround){grav = maxJump;}if (ground.hitTest(_x + (_width / 2), _y - (_height / 2), true)){_x -= speed;}if (ground.hitTest(_x - (_width / 2), _y - (_height / 2), true)){_x += speed;}if (ground.hitTest(_x, _y - (height), true)){grav = 3;}}

Thanks.

Link to comment
https://linustechtips.com/topic/204613-need-help-with-flash-platformer-game/
Share on other sites

Link to post
Share on other sites

Maybe you just suck at the game?!?!?

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

And where do I add the code? I'm sorry, I'm pretty much a code illiterate :/

I don't really understand the code for this myself, but you could have a collision function that makes the character follow the platform on the X Axis when it's colliding with it.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×