C#을위한 작은 탁구 게임을 개발 중입니다. 나는 충돌을하는 방법에 대한 일반적인 생각을 가지고 있지만 패들의 특정 위치를 지정하는 데 어려움을 겪고있다.특정 충돌 지점을 확인하는 방법
나는 폼을 타고 튀어 오르는 공을 가지고있다. (벽을 튀고있다.) 패들로부터 튀어 나올 수있다. 그러나 외륜에서 튀어 나오면 항상 같은 각도로 튀어 나온다.
내가하고 싶은 것은 외륜의 섹션 (예 : 왼쪽 모서리, 오른쪽 모서리, 가운데)을 지정하고 외륜을 치는 위치에 따라 각도를 변경하고 싶습니다.
누구든지 컨트롤의 섹션 (이 경우 그림 상자)을 지정하는 방법을 알아 내면 도움이 될 수 있다면 크게 감사하겠습니다.
편집 : 죄송합니다. 아직 명확하지 않았습니다. 내가 알고 싶은 것은 공이 패들에 닿는 곳을 어떻게 확인할 수 있는지입니다.
나는 환상 물리 기반의 각도 반사를 구현하지 않을 것이며, 단순히 직접 값을 할당 할 것입니다.
ball.Bounds.IntersectsWith (paddle.bounds)를 사용할 수 있다는 것을 알고 있지만, 이는 충돌 일뿐입니다. '왼쪽 가장자리, 오른쪽 가장자리'등과 교차하는 것과 같은 것을 지정할 수 있습니까?
다시 말씀 드리지만, 혼란 스럽습니다.
편집 2 :이 기능을 사용하면 몇 가지 문제가 해결 될 수 있기를 기대합니다. 현재는 저어요. 외륜은 단지 하나의 그림 상자이며 '공'은 그림 상자 안의 이미지입니다.
** pcbPluto는 '볼'입니다.
//bounce off user/ai paddles
if (this.pcbPluto.Bounds.IntersectsWith(this.pcbUser.Bounds))
{
//if it hits user's paddle, reverse y direction
intDirectionY *= -1;
}
else if (this.pcbPluto.Bounds.IntersectsWith(pcbComputer.Bounds))
{
//if it hits computer's paddle, reverse direction
intDirectionY *= -1;
}
당신이 볼 수 있듯이, 사용자 또는 컴퓨터의 패 중 하나를 타격시의 전류로, 난 그냥 수직 이동을 역. 이 문제는 공이 패들에 닿는 위치와 관계없이 각도가 고정되어 있다는 것입니다.
공이 패들의 특정 영역에 닿으면 각도가 달라지기를 바랍니다. 예를 들어, 가장자리에 부딪치게되면, 중간 섹션, 아마도 30도 각도에 부딪 힐 경우 가파른 각도로 나갈 수 있습니다.
다시, 혼란스럽게 생각합니다.
마지막 편집 : 알았습니다. 아래는 공이 그림 상자에 닿는 곳을 지정하는 데 사용한 방법입니다. 그 바탕에 반사 각도를 변경했습니다.
public void AiBallBouncer()
{
//variable declaration and assignment
double dblComputerRelativeLocation = 0;
dblComputerRelativeLocation = Math.Abs((((double)pcbComputer.Left - (double)pcbAsteroid.Left)/(double)pcbAsteroid.Width));
//check for if the ball bounces on the paddles
if (pcbAsteroid.Bounds.IntersectsWith(pcbComputer.Bounds))
{
//check for which angle of reflection to use
if (dblComputerRelativeLocation <= 0.1)
{
//reverse direction
intDirectionY *= -1;
//set new angle
intAngle = 30;
//increase speed
intSpeed += 2;
}
else if (dblComputerRelativeLocation <= 0.2)
{
//reverse direction
intDirectionY *= -1;
//set new angle
intAngle = 35;
}
else if (dblComputerRelativeLocation <= 0.4)
{
//reverse direction
intDirectionY *= -1;
//set new angle
intAngle = 50;
//set speed back to normal
intSpeed = 5;
}
else if (dblComputerRelativeLocation <= 0.6)
{
//reverse direction
intDirectionY *= -1;
//set new angle
intAngle = 60;
//set speed back to normal
intSpeed = 5;
}
else if (dblComputerRelativeLocation <= 0.8)
{
//reverse direction
intDirectionY *= -1;
//set new angle
intAngle = 50;
}
else if (dblComputerRelativeLocation <= 0.9)
{
//reverse direction
intDirectionY *= -1;
//set new angle
intAngle = 35;
}
else if (dblComputerRelativeLocation <= 1.0)
{
//reverse direction
intDirectionY *= -1;
//set new angle
intAngle = 30;
//increase speed
intSpeed += 2;
}
}
}
충돌 이전에 공이 가지고있는 각도를 가져 와서 입사각을 기준으로 각도를 변경하면 수학적으로 할 수 있습니다. 완전한 리플렉션을 사용하면 180도 각도로 그 각도를 취하게됩니다. – Emz
이 스택 교환 게시물 확인 http://gamedev.stackexchange.com/questions/4253/how-do-you-calculate-where-a-ball-should-go-when-it-bounce-off-the-bar – tophallen
확실히 프로그래밍 문제는 아니며 물리/수학 포럼에 속합니다. 수식을 얻은 후에는 수식을 구현하십시오. 구현에 특별한 문제가있는 경우 여기로 돌아와주세요. –