Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7737875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:07:05+00:00 2026-06-01T08:07:05+00:00

I’m currently working on a block world engine in XNA and can’t get the

  • 0

I’m currently working on a block world engine in XNA and can’t get the collision detection and handling to work properly. The world is in an array indexed with ( z * width * width + y * width + x ) and containing different blocks represented by bytes. All fine and dandy. Or so I thought.

I’ve tried different techniques for collision handling and I’m currently using a version where I calculate the players/cameras direction and before adding it to the position I check each individual vector (x, y and z) with half a units offset (to compensate for the block size of 1.0) against the world and only apply it when the result is zero. So far so good. Now the problem arise when I walk straight into a corner because the x- and z-axis does not intersect/collide until after I’ve come a bit into the cube.

So how am I to properly calculate collision detection and handling in a block world?

I would really like some input on this matter, and preferably on a higher/conceptual level, but code examples are of course welcome aswell.

To further explain my situation, based upon @A-Type’s response:

So, let’s be more precise here to help me understand you. My character is only one unit big in every direction, which should make things easier.

First of all, do you reccon I should update my characters position first and check for collissions after? This would be my prefered way of doing collision detection but if it’s any easier I’ll check first and move later if possible.

Well, I understand that the player can only be intersecting 8 cubes (in your example 12) and the rounding seems to be a very good idea too, but I don’t quite see the transition from the 12 cubes (again in your example, mine would be 8) to only 3. Wont this cause the same problem where the corners of the character-cube wont be taken into consideration?

I have tried to implement this but failed, so I thought more theory might do it. (I’ve actually gotten the collision detection to work but in those cases I lost my speed completely, not just in the colliding direction.)

Thanks for your time!
Karl

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:07:07+00:00Added an answer on June 1, 2026 at 8:07 am

    Alright, let’s give this another shot then. There are two basic phases to collision detection in any efficient system. There’s wide-phase and narrow-phase, if you will. Wide-phase uses inaccurate but cheap methods to determine if two objects could intersect, and passes those on to narrow-phase. Narrow-phase takes our two candidate objects and applies more complex physics to mediate the collision.

    With grid-based worlds, we have a very simple and advantageous method for broad-phase collision. That’s the grid itself. We can use the player’s position and size to determine the 8 blocks he could possibly be intersecting (we’ll use your case from now on). Note, in my original answer it did seem like I was talking about narrowing it down to 3 blocks– I was making it more complicated than it needed to be, especially for a 1-block character. The simplest method is this: round the center of your character to a corner of the grid, i.e. where the corners of 8 blocks intersect. Then select those 8 blocks for narrow-phase testing. Be sure to use midpoint rounding, not floor rounding as is default in working with integers. I.e., if a value is 1.53, it should round to 2, and 1.49999 rounds to 1.

    Now, narrow phase I didn’t really cover much. You asked whether to move first or after, I think you kind of need to do it first. I’m no master of physics simulation, but I know you first want to calculate the direction of collision (center of character minus center of block). The depth is the length of this vector. If your blocks are 1 wide, then you don’t want that length to be less than 1; that shows they are intersecting (somewhat basically).

    Now, there are many ways to ‘restore’ objects from a collision. I would suggest determining which axis the objects collide least on. That is, if the X component of your collision direction vector is the least, that means your player is closest to being out of the collision in the X direction. Apply an opposing force in that direction proportional to the depth of the collision in the X direction. Or, if you choose, simply set the position of your character to be the distance you want away and don’t bother with forces. But you’ll only want to move the character in one cardinal direction. This makes things simpler and doesn’t impede movement along the ground or along walls.

    Think of it this way: let’s say every frame your character falls .3 into the ground due to gravity. Now, let’s say that he’s in the center the block when he falls in this frame. That mean’s his collision depth with the block below him is (0.5, 0.3, 0.5) (where X is sideways, Y is up, and Z is forward). If you apply a restoring force in all of those directions, you’re going to be moving the player to the left, backwards, and back up over the ground. That last bit is the only part you wanted to do. So, ignore the larger axes of collision and only restore on the smaller (Y) one. Now your character’s horizontal movement is unimpeded and he stays above the ground.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.