Game Development Community

Collision Blocking

by StandardFace · in Torque Game Builder · 04/02/2010 (7:00 am) · 12 replies

I'm making a tetris-type game and for my purposes I'm not using a tilelayer to handle the game board. When I hit the button to make my 'active piece' move right, if there is a piece in the way, I want it to not move. Can anyone offer some advice on how I would do this? If I use collision detection I don't want the active piece to 'break' or 'touchdown' when it hits another piece from the side like it would if i matched up colors (etc...).

What would solve my problem, I'm thinking, is if I could test to see if a certain object is at a certain position. Something like:

%coordinates = $activePiece.getPosition();
if(isObject at %coordinates) <--------- This is what I'm not sure how to do.
{
doThis();
}

etc...

#1
04/02/2010 (5:01 pm)
Can anyone point me in the right direction? I'm thinking there is just a simple function I'm overlooking!

-SFS
#2
04/02/2010 (6:12 pm)
I'm not in a place where I can test this to be sure but I thought once you had a piece that came to rest you could call .setImmovable() on it, which I believe will allow you to still use collision detection if you want with your active piece. Otherwise it would seem to me that you'd have to keep track of every single fixed piece and check whether the object was approximate to its location (and that sounds like a pain).
#3
04/12/2010 (10:30 am)
Aaron, thanks, but the collision isn't the problem. I need to know if a certain position in world space has an object in it.

The logic that I need in plain english is this:

If at (positionX, positionY) an object of the class "play block" exists, then set a variable to false.

I would appreciate any help I can get...

-SFS
#4
04/12/2010 (6:29 pm)
Is there some way I can get some replies to my thread? Is there a reason one person gets 15 replies and so many other threads go unnoticed? I have what I assume is a simple question (compared to some others) so I don't understand...
#5
04/12/2010 (7:29 pm)
I can honestly say that I didn't answer your question because I didn't feel that the right question was being asked. You phrased your problem in one way (a tetris-type game), but then want to know where a single point is located. But let's try to fix it by going through iterations of your problem and coming to a solution.

First, if you just want the logic as you described, it would be something like:
// This tells us the name of the scene graph your piece is in.
%scene = $activePiece.getSceneGraph();

// This gets us the center of the active piece.
%pos = $activePiece.getPosition();

// This returns us a space-separated list of objects at this location.
%objList = %scene.pickPoint( %pos );

// This gets us a count of those objects.
%cObjList = getWordCount( %objList );

// This iterates over the list
for( %i = 0; %i < %cObjList; %i++ )
{
  %objAt = getWord( %objList, %i );
  // Now we have an object called %objAt that is at that position.

  if( %objAt.class $= "PlayBlock" )
  {
    $someVariable = false;
  }
}

It wouldn't hurt to look at this documentation for pickPoint. Typically you'll add an "exclude object" for which you'd pass in "$activePiece" so that it doesn't get added to the list.

You'll have to realize that at this point, the two objects will very likely be overlapping by quite a bit. You are comparing the center of one object ($activePiece) against the bounding box of another object (%objAt). If this isn't what you wanted, let me know and we can take this through another iteration.
#6
04/12/2010 (7:58 pm)
William, first of all, thank you for your response. I'm sure you can understand my sense of urgency. Sometimes it's difficult to know what question to ask!

I had been researching pickPoint(), so I was interested in seeing how it worked. This indeed is what I was searching for a better understanding of. This method works for my purpose, but...I have just (in the last 2 hours of working) come up with a system of logic to better address what I wanted to do. I'll have to wait to share the method of what I'm working on for now...

Thanks for the reply, also your link to the documentation really helped...I have a link to the main page of that document section but didnt know it went as indepth as that. I had been using the old T2D docs...

Thanks again

-SFS
#7
04/12/2010 (7:59 pm)
As an aside, I can tell you a few things.

First, all threads get read by many people. But since the types of games that people make are so varied, often times nobody has any clue how to answer a given question. Don't take it personally when your question goes unanswered; nobody may really know.

Second, it looks like about 5% of recent questions went unanswered. I personally try to look at all questions with no responses to see if I can at least give the person a foothold. It's very rare that I let a question go.

Finally, I'll agree that there is one person who gets a lot of attention. For one, it's fascinating to see the layers and folds of a train wreck. For another, he always misinterprets answers, so it requires a *lot* of re-clarification.

Hope that clears some things up! Now... let's get back to getting your game progressing!
#8
04/12/2010 (8:01 pm)
Cool! If you do run into any problems, just reply to this thread... I've got it tagged for replies.

Later!
#9
04/13/2010 (6:36 am)
Williams right. I wanted to offer up a response... I even had some ideas written down but after reading, they just weren't that helpful so I scraped it.

While a collision based Tetris does sound interesting; I still have to wonder why not use a tileLayer if you're still getting to grips with the engine?
#10
04/13/2010 (8:50 am)
I have written the system for our game a number of times (to discover the best method), including using tileLayers, using an object outside the tileLayer interacting with the tileLayer, and in its current state, no tileLayers.

I've been able to program the game so far using only resources on TDN and things I come across(NOT copy + pasting mind you...from scratch), but since it's a case of me teaching myself...of course there are things I don't understand or don't know, so I have to find workarounds and 'creatively' solve things. And that's the problem of course, self taught = maybe not the correct way always.

Sometimes I get too far into a method I can't clearly see if another method is better....but I'm thinking about going all tileLayer again.

The nature of our industry messes us over sometimes too...I bet if I told you exactly what puzzle system I was trying to imitate in TGB you would be able to tell me exactly how to do it (and typing that statement makes me want to do just that) but there's details that I just can't reveal etc etc...I wouldn't mind a private chat with someone sometime either if anyone is interested, but the titles and icons on this forum change so much that I don't know who does/doesn't work for GG and I can't expect anyone to offer advice for free!

Thanks for the help guys,

-SFS

#11
04/13/2010 (11:10 am)
If you want to email me (my email is in my profile), I could try and help guide you to the best system for a particular style of game.

Disclaimer: I've never written a platformer/Mario-style game, so that's by far my weakest area. I'm not a GG employee. I do have a game company with games in the works, games with mostly complete design documents, and games that are in the "idea" pipeline. My point here is that I can't guarantee that I'm not already working on your idea, but I can guarantee a non-disclosure.

So, if that disclaimer didn't scare you off, feel free to write!
#12
04/13/2010 (12:20 pm)
Alright William, I'll send an email later.

Thanks!

SFS