Zania day 18: AI 4

I am actually quite disappointed at myself for taking 3 days to figure this out. It was my pride that stopped me from progressing and keep on searching for a clever way to do  this. Alas, as days waste away, the urgency of the deadline finally pushed me to find the dumbest and surest possible way to implement the solution. Result? Well, I have finished the simple ai implementation and solved my physics problem with a dumb method. However, I am not able to show the world because debug mode introduces some time delay that would otherwise not be there in published code. So, now I am stuck with a non working published copy that has a null object reference error. The beauty of asynchronous calls.

A few things also popped up to mind as I read some thought ideas about idea centric vs action centric work style. I definitely need to find what the strong point of this game is going to be about, the audience I am targeting and what my strengths/skills are.

Note to self: review published code more often.

Completed work:

AI Targeting (Do this first):

  • Get Player position (done)
  • Get Current position (done)
  • Face player? (Done)
    • ApplyTorque (Done)
    • Radian calculation using atan2 (Verify)
      • Reversed the atan2 input to Math.atan2(playerPos.x – curPos.x, curPos.y – playerPos.y);  so that radian 0 is pointing up and radian goes from 0 to 2 PI in clock wise direction.
      • Need to figure out what happens when 2 PI is reset to 0.(done)
        • Dumb solution for now
        • if (curAng < 0) curAng += (2*Math.PI) ;
          if (destAng < 0) destAng += (2*Math.PI);
          if(curAng > Math.PI){
          curAng = (curAng + Math.PI)%(2*Math.PI);
          destAng = (destAng + Math.PI)%(2*Math.PI);
          }if (destAng > curAng){
          if (m_actor.m_body.GetAngularVelocity() < 0.5){
          trace(“right”  + m_actor.m_body.GetAngularVelocity());
          m_actor.ApplyTorque(10);
          }
          }
          else {
          if (m_actor.m_body.GetAngularVelocity() > -0.5){
          m_actor.ApplyTorque(-10);
          trace(“left”  + m_actor.m_body.GetAngularVelocity());
          }
          }
    • Problems
      • Limit radian range to one circle only and redo the calculation (Done)
      • Limit angular velocity for now (done)
      • Create a test system where there are no gravity nor planet to test the AI (Done)
      • Distance from player?
        • ApplyForce?
        • Distance calculation Uses Math.pow(x, 2) + Math.pow(y,2) instead because square root is too computing intensive (done)
        • Accelerate when nozzle points to player and player is outside of 100 square meters (done)
      • Player in weapon range?
        • Attack (done)
        • Shoot when player is within 50 square meters (done)
      • AI’s simple first iteration algorithm
        • Define player position, approach player, shoot when within range.

Incomplete work:

Change restitution for the bounce effect.

Null object reference at published work. Not seen in debug mode. (Do this first)

AI GetPosition call results in null reference. Body has not finished creation while the actor class has completed. Sigh… async calls.

Need to bring shooting action to the SolarSystem spawner and create a new constructor for bullets.

  • Right now it’s the ship that spawns the bullets.
    • Do I want ships to spawn the bullets?
  • Bullets does not need interaction with the rest of the system besides the physics
    • Physics already linked.
  • OnCollision event? Bullet upate? Or the solarSystem’s job?
  • Need to add timer to bullet lifetime otherwise the world will be filled with bullets that takes up computation time
    • Add a new constructor to actor class to create bullets
      • Ship need to get the orientation and speed vector of the firing body before calling bullet constructor
    • Destroy the bullet a few frames after collision
      • add collision variable to bullet constructor

Inventory display at Player.as Line 93 is done through debug GUI right now, so compilation is not possible without DEBUG::MODE on.

Need to change actor creation to be based on sol.xml loading. (See Sol class)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>