00:00
00:00
Newgrounds Background Image Theme

FylypFimpossible just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Platform Game 2009-07-10 13:58:58


Hi, I've started making a platform game and i'm having a bit of bother with collision detection when it comes the the player landing on the platform. heres the code

private function touching(e:Event)
{
if (Level.hitTestPoint(hero.x, hero.y, true) == true)
{
//trace("touching");
hero.vel = 0;
hero.y -= 1;
hero.Jump = false;
}
}

the problem is when the player is falling fast, he falls through the platform because he is falling faster than the height of the platform so the hitTestPoint co-ordinate never touches the platform.

Just wondering if anyone knows a way to solve this.

heres a link to my swf http://www.darrenfindlayportfolio.co.uk/
index2.html

Thanks in advance

Response to Platform Game 2009-07-10 14:01:18


**Code is in AS3

Response to Platform Game 2009-07-10 14:17:12


Make the platform bigger or the framerate higher...? Anyway, after your hitTestPoint, why has you done ... == true? It is uneccessary.


BBS Signature

Response to Platform Game 2009-07-10 14:18:22


Oh yeah, use a while loop instead. That way you don't have to rely on the framerate, which may be too small if they are falling fast.


BBS Signature

Response to Platform Game 2009-07-10 14:26:00


At 7/10/09 02:17 PM, Neo-13 wrote: Make the platform bigger or the framerate higher...? Anyway, after your hitTestPoint, why has you done ... == true? It is uneccessary.

yeah i thought about just making the platforms bigger butif the character falls from a great height he's still going to sink into the platform and then slowly move up. I dont think that increasing the framerate would help because the pixels per frame hes falling will still increase and he'l still fall into the platform.

Thanks for your reply though

Response to Platform Game 2009-07-10 14:27:34


That's why I changed my reply. See my second post.


BBS Signature

Response to Platform Game 2009-07-10 15:12:12


At 7/10/09 02:56 PM, U-Gamer wrote: would you like for anybody to help you with this game? I can. I'm looking for someone who can get help with their flash. (No I will not ask for cash, so you don't have to dig through that dump you call a pocket for your wallet).

Yeah that would be great!!

I got it working now btw, just added a few extra collision detections

if (Level.hitTestPoint(hero.x, hero.y, true))
{
//trace("touching");
hero.vel = 0;
hero.y -= 1;
hero.Jump = false;
}
if (Level.hitTestPoint(hero.x, (hero.y - 1), true))
{
//trace("touching");
hero.vel = 0;
hero.y -= 1;
hero.Jump = false;
}
if (Level.hitTestPoint(hero.x, (hero.y - 2), true))
{
//trace("touching");
hero.vel = 0;
hero.y -= 1;
hero.Jump = false;
}
if (Level.hitTestPoint(hero.x, (hero.y - 3), true))
{
//trace("touching");
hero.vel = 0;
hero.y -= 1;
hero.Jump = false;
}
if (Level.hitTestPoint(hero.x, (hero.y - 4), true))
{
//trace("touching");
hero.vel = 0;
hero.y -= 1;
hero.Jump = false;
}
if (Level.hitTestPoint(hero.x, (hero.y - 5), true))
{
//trace("touching");
hero.vel = 0;
hero.y -= 2;
hero.Jump = false;
}

Response to Platform Game 2009-07-10 15:18:12


Thanks for your posts neo and U-gamer

Response to Platform Game 2009-07-10 18:45:20


At 7/10/09 03:12 PM, darrenfindlay wrote:
I got it working now btw, just added a few extra collision detections

That method you used is called multisampling, but sadly you did it inefficiently. (copy pasting chunks of code with just one number changing)

So try this.

If your y velocity is in a variable called yspd:

var checks =10 // this is the amount of checks you want to do between your initial and final position
var sample=yspd/checks // this is an increment of yspd by which you'll check the collision
var hit = false; // a boolean variable (true / false ) tracking if there was a collision
for(var i =0;i<checks;i++){ // loop from 0 to 9 times
     if(ground.hitTestPoint(char.x,char.y+sample*i,true){
         hit=true; // assign hit true because there was a collision
         break; // exit the loop cause you already found a collision
     }
}
if(hit==true) { // or rather just if (hit){  same thing
//DEAL WITH COLLISION
} else { // otherwise
//no collision, move char down the full yspd
}

That'll severly shorten your code :) Hope it helps.

Response to Platform Game 2009-07-10 19:18:27


Thanks coolio!!

your post made a lot of differance to my game!

if(hero.vel > 0)
{
var checks = 20;

for(var i = 0; i < checks; i++)
{
if (Level.hitTestPoint(hero.x, hero.y - i, true))
{
//trace("touching");
hero.vel = 0;
hero.y -= i;
hero.Jump = false;
}
}
}

I changed the hero.y - 1 to hero.y - i and it stopped the character slowly floating up to the same level as the platform, now it looks much better !

plus my code is 10 times cleaner :)

thanks alot mate :)

Response to Platform Game 2009-07-11 01:03:41


games should have 30 fps so that doesnt happen. Increase fps and shrink numbers. also put a cap at the momentum around the thickness of the thinest platform.


My friend's sister plays wizard 101....

she's 17.....

wtf?

Response to Platform Game 2009-07-11 01:07:17


At 7/10/09 02:26 PM, darrenfindlay wrote:
At 7/10/09 02:17 PM, Neo-13 wrote: Make the platform bigger or the framerate higher...? Anyway, after your hitTestPoint, why has you done ... == true? It is uneccessary.
yeah i thought about just making the platforms bigger butif the character falls from a great height he's still going to sink into the platform and then slowly move up. I dont think that increasing the framerate would help because the pixels per frame hes falling will still increase and he'l still fall into the platform.

Thanks for your reply though

I made a script to fix that problem. i dont feel like typing it right now. im realy tired. i dont remember it very well. basicly make more hit tests slightly higher up in the character and make it increase its height if it touches the ground. It still might sink into the ground for one frame though


My friend's sister plays wizard 101....

she's 17.....

wtf?

Response to Platform Game 2009-07-11 11:34:32


At 7/10/09 07:18 PM, darrenfindlay wrote: Thanks coolio!!

your post made a lot of differance to my game!

Yep your way works too. :) Glad to help.