I am working on a platform game, and I can't seem to make the player stick onto moving platforms.
All of the platforms are in one movie clip called "level" and I added an animation in a movie clip for moving platforms inside the level. The player needs to stick onto the moving platforms, rather than remaining in the same position until the platform moves from under him.
Also, the platforms just won't be moving side to side or up and down, they will be moving all over the place in a random direction.
Easy Fix: Make the platform a half rectangle so the platform will have sides. That way when the platforms move there will be a wall blocking the character and preventing it from falling. Hope I helped,I can make it clearer for you if did not understand what I meant. Good luck.
Actually I found it out on my own after experimenting. onClipEvent (load) { distx = 0; disty = 0; } onClipEvent (enterFrame) { if (_root.Player.hitTest(this)) { _root.Player._x = this._x+distx; _root.Player._y = this._y-disty; if (Key.isDown(65)) { distx -= _root.Player.speed; } if (Key.isDown(68)) { distx += _root.Player.speed; } } else { distx = _root.Player._x-this._x; disty = _root.Player._y-this._y; } } I was so relieved when I got this down. All on my own too, so it is even more satisfying. I hope other people could use this script for help to.
Basically, I made a movie clip of the platform, and put that platform movie clip in another movie clip where it is being moved around (The player is not in the movie clip). My script only works when the platform isn't in a movie clip. While experimenting, I found a command called _root.localToGlobal and _root.globalToLocal. On the flash help window, it said that it can be used to translate x coordinates from in a movie clip to outside a movie clip, and vise versa. Is there anyway I could fit that code into the script to make it work?
Keep in mind before posting, IT DOES NOT HAVE A CERTAIN X OR Y SPEED. It is just an animation and I am trying to get the player static to the platform while on top of it.
Does the localToGlobal convert the variable itself, or what?
I don't need the hitTest to work. I need the x and y coordinates of the moving platform to be in global coordinates, so the distx and disty variable will be correct. The formula goes like this:
Yes, localToGlobal rather than returning a value, changes the value of the point.
localToGlobal changes a point form the local coordinate scheme (Where 0,0 is the center of the MovieClip), into the _root coordinate scheme where 0,0 is the top left corner. This function is mainly used when one or more parent MovieClips is being rotated. If you know all the parents of a MovieClip and they are not being scaled or rotated, then summing there coordinates will get you the global coordinates.
var globalX:Number=granddad.x+dad.x+son.x;
or
var po={0,0}; son.localToGlobal(po); var globalX:Number=po.x;