Jump to content
  • Advertisement

Tower Defense Indie Game Dev Blog #2: Obstacle Avoidance

EddieK

896 views

What have I done this week

This week I have fixed few bugs and finally implemented a fully working obstacle avoidance system which makes my pathfinding and collision/obstacle avoidance system done.

Some minor things which I did include:

  • Fixed bug where text rendering causes lighting issues
  • Added calculation of game entity's axis-aligned bounding box from data contained in .obj file
  • Added AABB to AABB collision detection and response
  • Added Ray to AABB intersection detection
  • Made the map size resizable

My own solution to obstacle avoidance problem

I had really hard time finding information about an easy way to do obstacle avoidance in the way I wanted it to be. So instead I worked few days and came up with my own solution which works pretty well. I think I kind of reinvented a wheel and someone might have a better approach to this problem than I do. But anyways, it's already done and it works the way I wanted it to, which is all I care about now.

What I wanted from my obstacle avoidance/collision system

For the obstacle avoidance system I wanted it to do few things:

  • Stop the vehicle if it gets too close to other vehicle
  • If vehicles are about to collide (traveling towards each other at the angle less than the threshold angle) then make them steer away from each other
  • Don't ever let two vehicles overlap

I tried and I failed

Before I explain how it works, I will say things which I tried and which didn't work that well.

First thing I tried was to create a separate AABB in the front of the enemy's car and check if it collides with any other car. If it does, stop the vehicle. I thought this would make it so that the vehicles wouldn't get too close to each other and hence wouldn't overlap. Well, that didn't work. Because when both vehicles collide to each other, they will both stop and will get stuck. To fix this, I added an if statement which checks whether the vehicles collide at each other if so, make it so that only one of two vehicles would stop and other would continue driving. But this made them overlap some of the times, which I didn't want. So after thinking for a while, I decided I should add AABB collision response, so that when cars hit each other they don't overlap, but get pushed back. So I did that and now it works pretty good, BUT if the vehicles are travelling towards each other there's no way of knowing which way to turn to avoid the collision. So I decided to scrap this AABB in front of the vehicle approach and try casting rays.

Approach which worked

My last and final try was to use rays instead of AABB to check for collisions with other entities. This time I say entities because I also want to check if the ray intersects the towers as well, this way we will know which way the vehicle can turn to avoid collisions.

So the way I do it is pretty simple. The vehicle casts number of rays from its center towards the front of the car which check for intersection between towers' and enemies' bounding boxes. Then I have a function which does some magic and calculates (from the ray intersection information) which way the vehicle should steer. This steering is only done if two vehicles are facing each other and moving towards. If they are not moving towards, I check if the ray distance is smaller than the threshold value and if it is I just stop the vehicle. There are other few tiny hacks and tricks which I did to polish the system. But this is mainly how it works.

Next week

I still haven't decided what I am going to do this coming week. But I think I will add different tower types, add GUI and make it so that enemies will spawn inside a building or in a hidden area from where they will come to the game's map.

You can see the state of the game here:

 

Twitter: https://twitter.com/extrabitgames
Facebook: https://www.facebook.com/extrabitgames
Website: http://extrabitgames.com

 



5 Comments


Recommended Comments

Awoken

Posted (edited)

Looks fantastic!  Are you raycasting for each vehicle?

Edited by Awoken

Share this comment


Link to comment
EddieK

Posted (edited)

12 minutes ago, Awoken said:

Thanks!

Yes, three rays from each vehicle every frame. There might be a better solution performance wise, but as of now I don't see any problems with framerates so I'll keep it the way it is for now. :)

Wait... Did I just accidentally edited your comment? 

Edited by EddieK

Share this comment


Link to comment
Awoken

Posted (edited)

lol, yes. 

Edited by Awoken

Share this comment


Link to comment
39 minutes ago, Awoken said:

lol, yes. 

Sorry :D 

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By KevDev
      [UNITY ASSET]
      Customizable lowpoly weapons and shields.
      - Full Version: http://u3d.as/1hvG
      - Free Version: http://u3d.as/1jZV
      You can get the character model used in the video here (for FREE!): http://u3d.as/1kP7
       
    • By _Flame_
      Hello.
      I'm tring to implement opencl/opengl interop via clCreateFromGLTexture (texture sharing)
          glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
      With such texture I expected that write_imagei and write_imageui would work but they don't. Only write_imagef works. This behaviour is same for intel and nvidia gpus on my laptop. Why is it and why there is no such information in any documentation and in the entire internet? This pitfall cost me several hours and probably same for many developers.
       
       
    • By Nilmani Gautam
      In this video we will learn to change the blender layout
       
    • By Hashbrown
      When importing sprites in Unity, we get a Pixels Per Unit option. The smaller the value, the larger it looks on screen. This is great for very small (50x32px) sprites I download.
      My question is, how can I accomplish this with OpenGL? Should I make the sprite larger in the frag shader? I don't want to scale the game object, I'd like the image to be rendered at the size I need without changing the scale, similar to Unity.
      No code needed, just some suggestions that put me in the right direction. Thanks!
    • By Michael Barth
      Hello there!
      So I want to understand this better. With OpenGL 4.6, support was added to be able to run SPIR-V compiled shaders. I've messed around with it, gotten it to work. It's a little bit more complicated to have to use UBOs for most things now. What I mainly want to know is what the benefits are. So I understand SPIR-V is bytecode, and that it's used by Vulkan and that because it's bytecode, there isn't any worry about wild inconsistencies across GPU vendors. When OpenGL is using SPIR-V, does it also benefit from this?
      Also, does this deal with micro-stutter that's caused by shaders being loaded for the first time using traditional GLSL and shader caching?
      I have some application that uses some really old version of GLSL, like GLSL 120, and I'd been thinking about updating it and properly supporting GLSL 460 compiled to SPIR-V. The application also uses DX9, so I was just curious how updating and using these new techniques with OpenGL 4.6 would stack up against the old GLSL or DX9 methods. I'm not expecting some magic performance benefit, I'm just legitimately curious if it'd be worth it to try.
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!