It is currently Sun Oct 22, 2017 6:39 am

All times are UTC - 5 hours




 Page 1 of 1 [ 4 posts ] 
Author Message
 Post subject: Ghost VMK 15 - Collision Detection
PostPosted: Tue Apr 07, 2009 8:20 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
In VMK 15A I show how to setup the collision codes that will be used by the collision detection system in Ghost Toast.

Preventing the user from walking through walls that are beside or in front of the player is explained and implemented in VMK15B. I briefly mention BSP in the video but I incorrectly referred to it as Binary Search Partitioning, I meant to say Binary Space Partitioning

Collisions with corners is handled in VMK 15C/D.


Offline
 Profile  
 
 Post subject:
PostPosted: Fri Jan 01, 2010 6:38 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
VMK15B is split into 3 separate files. You will need to use WinRAR to extract all the files from the three VMK15b1, VMK15b2, and VMK15b3 files you need to download.
  1. Select the first VMK15_xx_part1.rar file in WinRAR and choose the "Extract To" button in the toolbar
  2. Select a path location where you want to extract all the files and click the ok button
  3. When the VMK file is done extracting, a dialog will appear asking for the second VMK15b2 file.
    Image
  4. Click the Browse button and choose the VMK15B_xx_part2.rar file
  5. Repeat the last two steps again for the last VMK15b3 file


Last edited by Marek on Sat Dec 11, 2010 7:24 am, edited 1 time in total.

Offline
 Profile  
 
 Post subject: Round corners
PostPosted: Wed Nov 03, 2010 9:20 am 

Joined: Wed Dec 24, 2008 4:25 pm
Posts: 16
I took a break between VMK015C and 015D and thought about one thing that bothered me a little. With the given approach, the player can actually get closer to the corner than the buffer distance. That may not be a big deal to anyone else, but it disturbed my sense of symmetry. So I devised an approach that keeps the player at least the buffer distance away, and turns out to be a bit simpler in the math as well, I think.

Imagine a vector pointing from the corner to the player. That vector must be no shorter than the buffer distance. So all we have to do is check its length: if it's shorter than the buffer distance we just scale it and put the player there. I added a scale() and a length() function to the Vector2 class to get this. Here's the code for one corner; only the definition of 'corner' changes from corner to corner:

case CE_PXNZ: {
    Vertex2 corner = Vertex2(squareCenter.m_x + m_mapHalfScale, squareCenter.m_y - m_mapHalfScale);
    Vector2 radius = Vector2(targetPosition.m_x - corner.m_x, targetPosition.m_z - corner.m_y);
    if (radius.length() < m_collisionBuffer)
    {
        Vector2 shift = radius.normalize().scale(m_collisionBuffer);
        targetPosition.m_x = corner.m_x + shift.m_x;
        targetPosition.m_z = corner.m_y + shift.m_y;
    }
}


It seems to work okay, but if anyone sees anything wrong with it, I'd love to hear from you.


Offline
 Profile  
 
 Post subject:
PostPosted: Wed Nov 03, 2010 10:46 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
Fantastic idea and it does make the code much easier to implement!


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Baidu [Spider] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron