The Daily Click ::. Forums ::. Klik Coding Help ::. Can you detect collisions between layers?
 

Post Reply  Post Oekaki 
 

Posted By Message

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
21st January, 2011 at 15:00:32 -

Hello everybody!

Long story but I've got 2 different objects on different layers. Can you test for collisions between them?
I'm using MMF2 Developer. Any help would be great! Cheers xxxxxxxx

 
n/a

nim



Registered
  17/05/2002
Points
  7234
21st January, 2011 at 15:16:39 -

You can change an object's layer at run-time (Order > Move to Layer). Try adding events to move the objects to the same layer, check for a collision and then move them back to their respective layers again, in that order. Hope that makes sense and helps.

 
//

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
21st January, 2011 at 15:21:20 -

As far as I know, you can't do collision detection between objects on different layers (although I once had a game where a backdrop and an active were on different layers but still interacted, so it might, at the very least, be different for backdrops). If that ends up being the case, that you can't do detection across layers, you could check to see if one object is overlapping another by testing their X and Y positions.

Floor(Abs((X1-X2)/Width2))+Floor(Abs((Y1-Y2)/Height2))

Where X1 is the X position of your object, X2 is the X position of the object you want to test a collision against, Y1 and Y2 being similar but for the Y coordinate, and Width2 and Height2 being the width and height of the region you want to test. It will return a value of 0 if the object lies within the region, and anything higher than one if it doesn't. If this doesn't work it's because I deleted things weird; it used to be full of flags and specific object names.

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364
   

Post Reply



 



Advertisement

Worth A Click