나는 한동안이 인공 지능 방법을 연구 해왔다. 벽이 플레이어에게 자신의 길을 막고 있다면 적의 방향에 따라 기본적으로 int
이 있습니다. 이것은 대부분의 경우 작동하지 않습니다. 때로는 적군이 뚫을 수없는 갈라진 틈을 지나갈 수도 있습니다. 다른 시간에는 벽에 뚜렷한 간격이 생겨 붙어있을 것입니다. 내 코드를 첨부 하겠지만 너무 비효율적이거나 문제를 해결할 방법이 아니라면 내 방식을 완전히 바꾸지 않을 것입니다. 나는이 모든 것이 정상적으로 어떻게 수행되는지를 알고 싶다. 그래서 더 나은 (그리고 작동하는) 방법으로 구현할 수있다.게임 프로그래밍 ai : 플레이어를 찾기 위해 벽을 크기 조정 하시겠습니까?
내 코드 : 그것은 당신이 현재 구현하려고하는 것은 스티어링로 알려진 것 같습니다하지만, 이러한 일들이 일반적으로 수행하는 방식이 Pathfinding을 것
public void update(ArrayList<Wall> walls, Player p){
findPlayer(p.getX(), p.getY());
boolean isCollision = false;
System.out.println(isCollision);
//if movement straight towards the player is blocked, move along the walls
for(Wall w : walls){
if(Helper.isBoundingBoxCollision((int)(x + vectorToPlayer.getDX() * SPEED), (int)(y + vectorToPlayer.getDY() * SPEED), width, height, w.getX(), w.getY(), w.width, w.height)){
isCollision = true;
if(Math.abs(vectorToPlayer.getDX()) > Math.abs(vectorToPlayer.getDY())){
if(vectorToPlayer.getDX() > 0)
WALL_COLLISION = 3;
else
WALL_COLLISION = 1;
}
else if(Math.abs(vectorToPlayer.getDX()) < Math.abs(vectorToPlayer.getDY())){
if(vectorToPlayer.getDY() > 0)
WALL_COLLISION = 0;
else
WALL_COLLISION = 2;
}
}
}
//System.out.println(isCollision);
//set the direction to the straight on vector, to be reset if there is a collision on this path
direction = vectorToPlayer;
if(isCollision){
//reset the variable, don't mind that what this is named is completely opposite = PIMPIN'
isCollision = false;
//scale dem walls son, and see when the path is clear
for(Wall w : walls){
if(WALL_COLLISION == 0 && !Helper.isBoundingBoxCollision(x + SPEED, y, width, height, w.getX(), w.getY(), w.width, w.height)){
WALL_COLLISION = 3;
isCollision = true;
}
else if(WALL_COLLISION == 1 && !Helper.isBoundingBoxCollision(x, y + SPEED, width, height, w.getX(), w.getY(), w.width, w.height)){
WALL_COLLISION--;
isCollision = true;
}
else if(WALL_COLLISION == 2 && !Helper.isBoundingBoxCollision(x - SPEED, y, width, height, w.getX(), w.getY(), w.width, w.height)){
WALL_COLLISION--;
isCollision = true;
}
else if(WALL_COLLISION == 3 && !Helper.isBoundingBoxCollision(x, y - SPEED, width, height, w.getX(), w.getY(), w.width, w.height)){
WALL_COLLISION--;
isCollision = true;
}
}
//if there is NOT a wall on the designated side, set the vector accoridingly
if(isCollision){
if(WALL_COLLISION == 0)
direction = new NVector(0, 1);
else if(WALL_COLLISION == 1)
direction = new NVector(1, 0);
else if(WALL_COLLISION == 2)
direction = new NVector(0, -1);
else if(WALL_COLLISION == 3)
direction = new NVector(-1, 0);
}
}
x += Math.round(direction.getDX()*SPEED);
y += Math.round(direction.getDY()*SPEED);
}
Eric B가 말한 것처럼 충돌 감지 기능이있는 조향 장치가 목적지에 도달하는 것이 보장되지 않습니다. 제안 된 Pathfinding 알고리즘으로 옮기는 문제는 알고리즘을 구현할 때 (A * 알고리즘이 여러 곳에서 문서화되어 있음) 적은 양이 될 것이지만, 그러한 알고리즘을 작동 시키려면 전 세계를 분리하는 데 어려움이있을 것입니다. isBoundingBoxCollision() 호출에서 엔진 자체를 활용하여 벽을 찾으려고합니다. 많은 게임은 이동 시스템을 쿼리하기가 쉬운 이동 메쉬로 레벨 지오메트리를 보강하여 지오메트리 분석의 복잡성을 피합니다. – Godeke
확인해 주셔서 감사합니다. – ceptno