View Full Version : [AS2] My Collision System (money awarded)
xdeath
09-25-2008, 02:36 AM
ok well basically here is the story i have this game underway i've been posting this trying to get someone to do this for weeks now and i think i've waited long enough don't you?
well basically my collisions aren't pixel perfect and they often go in the platforms before it stops. that's the first part that needs fixing then my falling system when you walk off a platform i feel that you fall at a different speed then when you jump and start falling. that need fixing also and the last thing i need fixing is a problem with my platform when you jump and let go of jump button if your in the platform my character will stop inside the platform and i need it so it will only stop if you land on top of the platform.
now i need this A.S.A.P and i'm willing to pay who ever solves the whole problem $50-60. so i hope someone will help me i will also put you in the game credits. so please do this for me.
here is the FLA file: Click Here (http://willhostforfood.com/files2/5780456/supernatural%20collison%20fix.fla)
drumn4life0789
09-25-2008, 08:26 AM
there was a good thread on here a while back about pixel perfect collisions you will just have to look around. People here like to help people they dont like to do things for you.
xdeath
09-25-2008, 08:57 AM
that's the thing the tutorials teached me my method of hitTests was good but not the best way i used there way and it made the collisions not as bad but the problem still consists and i think all the problems lie in my jump code and no matter how many tutorials i view it just isn't what i'm looking for.
drumn4life0789
09-26-2008, 01:02 AM
have u tried making the piece move back up to the level of the object it is hittesting with. I say this because the HitTest function is not so good when object are moving fast. I know yours are not moving very fast but it is still effecting it. So try in the hitTest code once it knows it hit it. Move the y value to where it should be.
xdeath
09-26-2008, 01:30 AM
if something goes to fast it isn't the hittest function that is bad it's actually flash see it's how it works it moves a few pixels and then it will skip some and repeat the process. in my case it would only affect like 2 or 3 pixels, which i can accept.
but if my collisions are perfect on some jumps and as i stay in air longer they become less perfect and my character winds up going right throught blocks sometimes. it isn't that bad anymore but i changed the hitTests to the height of my characetr divided by 2 and it improved it but the problem is still there. can anyone solve this for me or at least tell me were the problem is. (as in what part of the code is causing the problem)
drumn4life0789
09-26-2008, 06:04 AM
honestly man Im telling you. The problem comes from the hittest function. There is nothing wrong with your code it is just something that you have to mess around with to see what works the best.
drumn4life0789 is right. The only way to "fake" a perfect collision is to reset the object to where it should be. I said it many times on thread like this and often people with no experience refuse to listen and believe in this solution. They don't know that's what the professionals do! Also, Flash has no more problem with detecting collision than other programming language. Use C++ or Java, write your code the same way, and your object will still go a bit inside the floor. That's because you move your object a certain amount of pixel between each update of the screen (Flash, Java, C++ and other) so if the object at the next screen update passed the floor, the collision is detected so the object stops falling but it's a bit inside the floor. If you tell Flash to move an object 10 pixel between each screen updates, then that's what it does! Why would it stop at the floor? So, like I said, reset the object to the right position once you detect a collision!
http://www.actionscript.org/forums/showthread.php3?t=180985
xdeath
09-27-2008, 06:18 AM
it's not that i don't believe you. but i argue this because if you tested it as much as i have you will see that as you jump from platform to platform you will sometimes land on top of platform and as you stay longer in the air and depending on angle of movement it often goes inside the platform and i know it has something to do with my jump system i just can't figure out what is causing it.
drumn4life0789
09-27-2008, 06:46 AM
but it is not because u float longer in the air sometimes it is because you are hitting the ground at different times with your frame rate. like when you make gravity something like this
gravity -= 10;
or something like that. One time it might start that last minus 10 5 pixels above so it drops 5 pixels through before it test to see if it hit something. And if is at 1 then it will be 9 pixels into the object. That is what causes it to go in to the object u are hittesting with.
just change code to once it hits an object make it go back up to the x value of that object it will work.
xdeath
09-27-2008, 06:51 AM
yes but the floor at the bottom i fall down at like 23 speed and it was perfect collisions? whats up with that.
drumn4life0789
09-27-2008, 11:27 PM
obviously your not listening so im done.
xdeath
09-29-2008, 02:23 AM
it's not im not listening to you. its just i've seen games that do that and they don't work well for art based games. plus i still think it has something to do with my just\p system but i was going to do what you said when i came across an engine which supported slope movement and has somehow made perfect collisions well when your on straight ground they are perfect and that's what i need but i can't figure out how they did it.
the engine is called art based slopes.fla
if (falling == true) {
/* if(fall<maxfall){
_y += fall;
fall++;
} else if (fall>=maxfall){
fall = maxfall;
_y +=fall;
}*/
_y+=1;
}}
Try this out, and it'll stop right on the edge. Try a larger number like 10, see where it stops. Think about why don't you get the same problem when moving sideways.
xdeath
09-30-2008, 02:57 AM
i will try that when i get home soon. thanks so much for trying to help with this.
and no i don't get the same problem sideways probably because i'm doing it the same way in your code you just listed :)
but now you mention it if i get close to the edge of a platform i fall off and a part of my character will be in the block but other than that it works fine.
Headshotz
10-07-2008, 05:54 AM
Hi.
I re-wrote your code to make a few changes, while keeping many of the concepts in tact. The code below all goes in the frame and it does the exact same thing your old one did but without getting stuck at weird sections of platforms.
Also I've introduced invisible boundaries, I find these much easier in the production of a game overall, all you have to do to determine what is a platform and what is a wall is create a box over a particular area (try to keep the platform boxes the same height because the code atm doesn't adjust to all different heights) and give the box an instance name of wall+number or platform+number.
e.g:
wall1
wall2
platform4
platform5
If you exceed 100 walls/platforms then just adjust the variable to whatever you need. Also make sure there's a platform over the top of every wall reachable by a player so that the player doesn't get stuck in the middle of the wall.
I've included the modified .fla in case you don't get anything I just said. The boundary boxes will automatically go invisible when you run the game.
Here is the code:
//Headshotz/Treppy
//init vars - deleted some redundant variables
var movespeed:Number = 5; //x/y movement speed
var falling:Boolean = true; //Falling bool
var velocity:Number = 12; //Speed & Height
var gravity:Number = 0; //Fall renamded for intrinsic purposes
var ps:Boolean = false; //Pause bool
var maxbox:Number = 100; //This is how many boundboxes you have
var i:Number = 0; //i is the worlds most popular incremental variable name choice
var touching:Boolean = false; //Check if there's any contact
//Function makes all boundboxes invis
function hideboxes():Void
{
for(i = 0; i < maxbox; i++)
{
_root["platform"+i]._alpha = 0;
_root["wall"+i]._alpha = 0;
}
}
hideboxes();
//Pause screen control
pause_screen._visible = false;
pause_screen.pause_btn.onRelease = function()
{
_root.ps = false;
_root.pause_screen._visible = false;
}
//init main
onEnterFrame = function()
{
if (!ps)
{
//Makes the player fall
p1._y += gravity;
touching = false; //Something to call touching false if the for loop doesn't tell us otherwise
for(i = 0; i < maxbox; i++)
{
if((p1.hitTest(_root["platform"+i])) && (p1._y <= (_root["platform"+i]._y - (_root["platform"+i]._height/2))) && gravity >= 0)
{
falling = false;
gravity = 0; //Gravity reset
p1._y = ((_root["platform"+i]._y) - 23); //Change depending on platform height
touching = true; //Change bool inside
}
}
if (!touching)
{
falling = true;
}
if(falling)
{
if (gravity < velocity)
{
gravity ++;
}
//Part of his animation code goes here
if (gravity < 0)
{
p1.gotoAndStop(2);
p1._rotation += 12;
} else {
p1.gotoAndStop(2);
p1._rotation = 0;
}
}
//Character controls and the like
if((Key.isDown(Key.UP)) && (!falling))
{
gravity = -12;
falling = true;
}
if(Key.isDown(Key.LEFT))
{
p1._x -= movespeed;
if(!falling)
{
p1.gotoAndStop(1);
}
for (i = 0; i < maxbox; i++)
{
if (p1.hitTest(_root["wall"+i]))
{
p1._x += movespeed + 1;
}
}
}
if(Key.isDown(Key.RIGHT))
{
p1._x += movespeed;
if(!falling)
{
p1.gotoAndStop(1);
}
for (i = 0; i < maxbox; i++)
{
if (p1.hitTest(_root["wall"+i]))
{
p1._x -= movespeed + 1;
}
}
}
if ((!Key.isDown(Key.LEFT)) && (!Key.isDown(Key.RIGHT)))
{
p1.gotoAndStop(2);
}
//Pause
if(Key.isDown(Key.SPACE))
{
ps = true;
}
} else {
pause_screen._visible = true;
}
}
I hope this is somewhat helpful. I didn't add in the roof barrier because I assumed you wanted to be able to jump through the bottom of platforms. If you have any questions, just ask.
Edit: Deleted the variable "cap" because I never actually used it
xdeath
10-13-2008, 01:34 AM
i don't know how to thank you. i need this so much, so i thank you and will make sure your at the top of the credits so people are bound to see you before they lose focus and skip them. :) (providing this works of course)
i haven't actually tested this yet as i don't have flash on me. but i will test it later and will edit this post once i get back online.
edit:
ok tested it the collisions work, they aren't pixel perfect but they work so i will make the platforms not visible and place graphics according to were they keep landing. so thanks again. lol. i also noticed that you reset the position of character but it isn't that bad as it still looks natural so is good. so thanks again. still yet to look at actual source but i viewed swf file to test.
Headshotz
10-13-2008, 06:30 AM
Glad to see I could help.
xdeath
10-14-2008, 03:18 AM
also do you want me to credit you for this and if so what should do you want me to credit you as "Headshotz"?
i realized when i looked art code and went to start a basic credits page so i don't lose track of things that i should follow it up with you. :)
Headshotz
10-16-2008, 08:16 AM
Don't worry about crediting me, I only really get people to credit me when they use my original ideas or my software as part of their project. I did write the code above from scratch, but the concept is so common I wouldn't care what anyone did with it.
:]
|
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.