나는, 그것은 회전 '레이저 시력'회전하는 라인의 충돌 감지를 어떻게 변경해야합니까?
public Rectangle getLaserBox() {
float lOriginX = (leon.getPosition().x + 0.27f);
float lOriginY = (leon.getPosition().y + 0.7f);
float lEndX = lOriginX + (float)Math.cos((leonAimLaserSprite.getRotation())/57) * 5f;
float lEndY = lOriginY + (float)Math.sin((leonAimLaserSprite.getRotation())/57) * 5f;
Rectangle laserBox = new Rectangle(lOriginX, lOriginY, lEndX, lEndY);
return laserBox;
}
가 그럼 난 사각형의 중복 확인하고 경우 '레이저 눈'스프라이트을 단축하도록되어 방법을 가지고이야 내 "라인"에 대한 사각형을 만들 겹침이 감지됩니다. 내 렌더링 메서드에서 laserCol() 메서드를 호출합니다. MVC를 깨고 그냥 작동하려고 시도하고 있습니다. 내 laserWidth가 레이저 스프라이트의 너비로 적용됩니다.
private float laserWidth;
public void laserCol() {
Vector2 laserOrigin = new Vector2(leon.getPosition().x + 0.55f, leon.getPosition().y + 0.7f);
boolean laserIsCol = false;
for (Tile t : world.getTiles()) { //pulling in tiles as t, from world method getTiles()
laserWidth = laserOrigin.dst(t.getPosition().x + 0.1f, t.getPosition().y + 0.7f);
if (Intersector.overlapRectangles(getLaserBox(), t.getBounds())) {
laserIsCol = true;
}
}
if (laserIsCol) {
for (Tile t : world.getTiles()) { //pulling in tiles as t, from world method getTiles()
laserWidth = laserOrigin.dst(t.getPosition().x, t.getPosition().y + t.getBounds().y);
}
}
if (!laserIsCol) {
laserWidth = 8f;
}
}
그러나 스크린 샷에서 볼 수 있듯이 레이저는 짧아지지 않습니다. 다른 예제를 살펴 봤지만 더 좋은 방법을 이해하지 못하는 것 같습니다. 그래서 내 코드에서 thing이라는 객체를 추가 한 후 작성한 스프라이트 경계 상자를 확인하기로 결정했습니다.
는 그 후, 나는 몇 가지 코드를 변경하고, 광선을 사용하려고하고, 나는 다소 작업을받은 적이 있지만 내가 원하는만큼 그것은, 어떤 제안 가까운 아니에요?
public Ray getLaserRay() {
lOriginX = (leon.getPosition().x + 0.27f);
lOriginY = (leon.getPosition().y + 0.7f);
lEndX = lOriginX + (float)Math.cos((leonAimLaserSprite.getRotation())/57) * 10f;
lEndY = lOriginY + (float)Math.sin((leonAimLaserSprite.getRotation())/57) * 10f;
laserO = new Vector3(lOriginX, lOriginY, 0);
laserD = new Vector3(lEndX, lEndY, 0);
Ray laserRay = new Ray(laserO, laserD);
return laserRay;
}
private float laserWidth;
public void laserCol() {
Vector2 laserOrigin = new Vector2(leon.getPosition().x + 0.55f, leon.getPosition().y + 0.7f);
boolean laserIsCol = false;
if (Intersector.intersectRayBoundsFast(getLaserRay(), thing.getBB())) {
laserIsCol = true;
}
if (laserIsCol) {
laserWidth = laserOrigin.dst(thing.getPosition().x, thing.getPosition().y);
}
if (!laserIsCol) {
laserWidth = 10f;
}
}
나는 충돌 감지가 작동하도록하기 위해 2 개 선 세그먼트를 사용하여 끝났다. 나는 레이저 시력을 위해 하나를 만들었고, 내 물건 (적)을 위해 하나는 낮은 x 지점에서부터 x 지점까지 확장했다. 기본적으로 libgdx에서 세그먼트 intersector를 사용하는 것을 제외하고는 동일한 코드입니다.
누구나 레이저 광경에서 총알이나 피해를 만드는 방법에 대한 아이디어가 있습니까?
코드를 추가하지 않아도 문제를 진단하기가 어렵습니다. 아직 디버거를 사용하여 단계별로 진행 했습니까? – Thomas