Results 1 to 2 of 2

Thread: Best way to approach Collision detection

                  
   
  1. #1

    Staff Best way to approach Collision detection

    Now that i have finished my animation code (finally...lol) I am going to make a collision code.

    Now, i know how to do the map collision (stopping player falling of the screen) but am wondering about the best and easyest to add to way of doing things such as object and enemy ai collision.

    If you have any advice on the best way to approach it, that would be great.

    BTW, this isn't for Future-Resurection, It's for a secret game im coding!

    No details on it yet, but expect it to be big!

    hopefully it will be out in about 1 or 2 months! And fully playable

  2. #2
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    83

    Default

    Falling off the edge of the map or edge of the physical screen?

    The easiest method for the latter is to set a bounding area:

    if sprite.x < 0 then
    sprite.x = 0
    elseif (sprite.x + sprite.width) > screen.width then
    sprite.x = screen.width - sprite.width
    end

    if sprite.y < 0 then
    sprite.y = 0
    elseif (sprite.y + sprite.height) > screen.height then
    sprite.y = screen.height - sprite.height
    end

    Edit: misread post. for the enemy to player, box collision will suffice. See my example code in the Dev forums.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •