Thread: Object/collision avoidance in 2-dimensions

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    7

    Question Object/collision avoidance in 2-dimensions

    Hello. Is there any way to do simple collision avoidance for a system where one object is being chased by two others? The "prey" should be avoiding the "two predators". Two dimensional would be preferred. I can't seem to get anything to work correctly . Thank you! Here's the list of variables I'm using...(for reference)
    Predator 1's x-coord: alpha
    Predator 1's y-coord: beta
    Predator 1's angle (from x-axis, angle>=0): theta
    Predator 2's x-coord: iota
    Predator 2's y-coord: kappa
    Predator 2's angle (from x-axis, angle>=0): delta
    Prey's x-coord: epsilon
    Prey's y-coord: zeta
    Prey's angle (from x-axis, angle>=0): eta

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    The simple answer is yes. A somewhat longer answer is it depends on what you call simple. Having worked on a collision detection system a while back, it's not as simple as it seems, depending on borders, etc., though I wouldn't doubt that game programmers have stock algorithms written for this type of thing, as it's the basis for many games. You might get a more sophisticated answer on the gaming board.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    7
    thanks, I'll try there

  4. #4
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Try handling the direction and speed (velocity) of your objects as vectors. That way you can work out the distance between objects easily, you can calculate new positions simply by adding the velocity vector to the position at each time step. Furthermore, you can reverse the direction of your prey object when a preditor comes too close simply be reversing the sign of its velocity. Alternatively, your objects can have a 'thrust' vector which acts to change the velocity (accelaration) for a more realistic effect.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 45
    Last Post: 04-02-2008, 09:10 AM
  2. 2-d object avoidance. Help please! (basic stuff, I think)
    By charbach007 in forum Game Programming
    Replies: 4
    Last Post: 06-15-2004, 03:49 PM
  3. Array with user-defined dimensions
    By Jasel in forum C++ Programming
    Replies: 2
    Last Post: 11-02-2003, 09:58 AM
  4. Create a matrix with user-defined dimensions
    By EliasK in forum C Programming
    Replies: 2
    Last Post: 04-08-2003, 07:09 AM
  5. Dimensions.
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 08-19-2002, 08:03 PM