Detecting an obstacle in the path?

RocketBrainRocketBrain Member, PRO Posts: 269

So i'm using a tank to practice pathing and such so i'll use it in my example

Right now theres a tank. I touch the tank then touch where i want it to go. It rotates to face then moves. The issue i'm having is where the player might touch a target on the other side of an obstacle such as a wall or a house. I'd really like it if the actor would simply not do it and display "invalid placement" BUT in order to do that i'd need it to detect that there is something in the way before it moves.

any ideas? I've messed around with spawning an invisible line the width of the tank that detects when its over obstacles and sends that message to the tank not to go but is there a behavior method?

Comments

  • louistrudellouistrudel Member, BASIC Posts: 15

    @RocketBrain said:

    any ideas? I've messed around with spawning an invisible line the width of the tank that detects when its over obstacles and sends that message to the tank not to go but is there a behavior method?

    If you want good pathfinding I would suggest to use the the Path find behavior (A*pathfiding)

    This implies
    -you build your game with grid based thinking
    -your obstacle should have a definite width and height of multiples of your "grid size"
    (ex GridSize = 20, Obstacle height and width could be 20,40,60,etc...)
    -you obstacles should be placed in the middle grid squares (ex: positionX =20,40,60,etc.)
    -tanks should be no bigger then grid size
    -this will allow your tank to path trough mazes
    -the grid is pure math it doesn't need to show

    First
    -create a Table made of integers : TablePath
    -Create a table of two integer colums : TablePathOutput

    **Second **
    -create game attribute GridSize
    (this will be the resolution of your pathing)

    have your obstacles

    -detect they Col and Row in the table
    ex: row = self.positionX/GridSize
    ex: col = self.positionX/GridSize

    • change TableCellValue.TablePath(row,col) To -1
      (this will tell the pathing behavior this square is unpassable)

    Third
    -Use pathfind behavior with your tank (check the cookbook for details)
    -Use the TablePathOutput to move your character

    ETC
    this is only the general idea, tanks should also change the square they are on to -1 in the grid

    • maybe set all the grid values to 1 at first. so if you have tiles that should be avoided and can still be passed over if there is no other option they can have greater values.

    SECOND IDEA

    use many line actors to detect incoming obstacles so if the middle one is blocked change the direction in direction of the closest one that is not blocked

  • RocketBrainRocketBrain Member, PRO Posts: 269

    yeah i saw the pathfinding. thats not what i'm looking for.

    if obstacle is between tank and target don't move. i don't want it to find the path.

  • louistrudellouistrudel Member, BASIC Posts: 15

    just spawn an actor that move quickly to targeted move location and if it collides with an obstacle don't move?

  • RocketBrainRocketBrain Member, PRO Posts: 269

    my father was talking about adding the width of the tank to the calculation of the wdith of the obstacle, finding the outside points and then calculating if the path would take the tank in between those two points via vectortoangle. trying to figure that out.

  • louistrudellouistrudel Member, BASIC Posts: 15

    smart indeed

  • RocketBrainRocketBrain Member, PRO Posts: 269

    simple method:

    Distance.Target = Magnitude(....)
    Spawn actor.Guide:
    Width=width of tank,
    height= Distance.Target
    Position=Distance.Target/2

    If overlap/collide with obstacle
    change invalid.placement = true

    in the tank move rule include condition of invalid.placement=false.

    seems to work so far.

Sign In or Register to comment.