Forum Topic: Collission detection help!

(92 views • 3 replies)

This topic is 1 page long.

<< < > >>
Questioning

evilapple513

Reply To Post Reply & Quote

Posted at: 4/22/09 01:37 AM

evilapple513 FAB LEVEL 04

Sign-Up: 11/01/07

Posts: 5

I'm pretty new to FLASH game programming and I need help!

I'm making a side scrolling, adventure game and the main character is running away from an enemy. I want to make the character stumble through obstacles like chairs and tables along the way but the collision detector doesn't work all the time.

I want to know if there's a code that tells the detection boxes react to certain sides since I don't want it to over react like it's doing now or completely ignoring it at times.


None

OctoFlash

Reply To Post Reply & Quote

Posted at: 4/22/09 08:03 AM

OctoFlash DARK LEVEL 17

Sign-Up: 12/02/06

Posts: 839

wow you should really learn more simple stuff before trying to make such a hard to create game.. what you're asking here isn't just a simple code line we can give you..

BLAM DAMN SPAM. That rhymes! So what do we learn?
the right answer for the most bbs-posts: THE FREAKIN' COLLAB RULES!!!

BBS Signature

None

Nisas

Reply To Post Reply & Quote

Posted at: 4/22/09 08:08 AM

Nisas DARK LEVEL 06

Sign-Up: 04/04/09

Posts: 144

The hitTest function is a pretty limited one. You can't tell what side was collided with. To do that, compare the x values of the objects.

if(this.hitTest(object)){
   if(this.x > object.x){
      //collided with the right side
   }
   if(this.x < object.x){
      //collided with the left side
   }
}

Signatures are for people who aren't lazy.


None

atomoxic

Reply To Post Reply & Quote

Posted at: 4/22/09 06:29 PM

atomoxic LIGHT LEVEL 10

Sign-Up: 02/16/09

Posts: 226

A perfect collision code where you can react with all different shapes of objects is very complicated. Especially if your going for rounded objects and slopes. However if you are just after rectangluar objects (or objects almost rectangluar objects) you can just use a basic hitTest to do this.

If you are going to use rectangles then use this:

onClipEvent (enterFrame) {
    if (this.hitTest(_root.table) {
        // Make things happen when the table is hit.
    }
}

However if the other is what you are after I dont suggest this for a first game.

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 02:37 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!