Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to calculate a collision course in 2D

Discussion in 'Physics' started by sngdan, Oct 29, 2016.

  1. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,131
    As part of the enemy AI, I would like to calculate a collision course with the player.

    Problem Description:
    • Enemy and Player are moving objects best represented by an axis aligned rectangle in 2D space
    • Working in 2D space and not using the physics engine (i.e. calculate position and collision in code)
    • Both enemy and player move via acceleration and direction. i.e. described as vectors: position = position + velocity * t; velocity = velocity + acceleration * t
    • Restrictions: minimum speed: 0, maximum speed: yes, different for each, maximum steering angle: yes, different for each but between -45 and + 45 (0 being upwards).
    • Enemy AI Observes at t=0, its own position & velocity, the players position & velocity and assumes player's velocity to stay the same.
    • How does the Enemy need to adjust its own speed and angle (assuming a collision is possible) to hit the player as fast as possible (i.e. t = ?) with the maximum speed (in case player is in front at observation) or minimum speed possible (in case player is behind at observation)
    I would be interested to get pointed towards a C# solution for this. I did a google search on the subject and did not find what I needed (I might have used the wrong search terms), but I found some things that might help me develop a solution by myself. In case I do, before someone responds, I will post here.

    Thx!

    PS: In case I did not describe the problem sufficiently, please let me know what needs clarification. I do not want to waste anyones time.
     
  2. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,131
    beastofthegame likes this.