alright, so I am working on my first platformer, and have been working on the walls, floors and platforms. I have my character successfully staying on the floor, but that's where the success ends. On one wall, the character goes halfway into it before stopping, on the other he has about a half a wall of space before the wall. And it just plain doesn't recognize platforms. Here is my code, can you tell me if anything is wrong with it?
onClipEvent(load){ var ground:MovieClip = _root.ground; var grav:Number = 0; var gravity:Number = 2; var speed:Number = 5; var maxjump:Number = -18; var touchingGround:Boolean = false; }
Yeah, the FPS determine the speed of your "onClipEvent" loop, so a faster loop means more precise detection
hitTest itself is not very precise, there's this code I call "future X", which instead of checking if a colision happened, you check if a colision will happen
If you walking forward at a speed of X + 5, ou can check if your current X + 5 will go inside another object's X left border, so you stop it a loop before it actually goes in, so you can react, making it stop and positioning it to the limit of the object's X left border
ah, ok. Well, I'm rather new at actionscript, so i will probably stick with the code I currently have. I guess I can screw around with it until it fixes itself.
if the character runs halfway into a wall and stops half a body before the other wall my guess would be that the characters registration point is not centered. Go inside your character movie clip and make sure the registration point (the little + symbol) is in the center, you can use the align tools (->Windows->Align) to do this perfectly.
God damnit, sorry about that. My gf is in a weird mood today, which includes messing up my posts. If there's a mod watching, just delete that one.
Anyway, about your code. First off, are your platforms also embedded in the 'ground' movieclip? If they are, it's pretty weird that you wouldn't be able to walk on them. Also, your code for managing the gravity is pretty weird... why use the 'while' you have there? Also, if you're going for speed, try and keep the hittests down to a minimum... you could try and find an alternative to the five you have there, and use just one or two.
If I have the time, I'll see if I can rewrite some stuff for ya
Hey PixelSmash, thanks for the response. I finally fixed my platforms, and the character, so it's all working smoothly now. If you feel the urge to rewrite the code though, feel free, It would be really helpful.