Publish:

ํƒœ๊ทธ: , ,

์นดํ…Œ๊ณ ๋ฆฌ:

๐Ÿ“Œ ํšŒ์ „ํ•˜๋Š” ๋ ˆ์ด์บ์ŠคํŠธ

๐Ÿ“‹ Raycast

ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ์žฌ์‚ฌ์šฉ ํ•˜๊ธฐ ์œ„ํ•ด ์ปดํฌ๋„ŒํŠธ๋กœ ๋งŒ๋“ ๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
class BLOGPROJECT_API URaycast : public USceneComponent
{
public:
  UPROPERTY(EditAnywhere)
  float Distance;
  FVector StartPos;
  FVector Forward;
  FCollisionQueryParams Params;
  FCollisionObjectQueryParams ObjectParams;
  FHitResult HitResult;
};

FCollisionQueryParams ์™€ FCollisionObjectQueryParams ๋Š” ์ถฉ๋Œ์ฒด ๊ฐ„์˜ ์„ค์ •์„ ํ•˜๋Š” ๊ตฌ์กฐ์ฒด์ด๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void URaycast::BeginPlay()
{
  Super::BeginPlay();

  StartPos = GetComponentLocation();
  // ์ž์‹ ์€ ์ถฉ๋Œ์—์„œ ์ œ์™ธ
  Params.AddIgnoredActor(GetOwner());
  // PhysicsBody ๋ฅผ ์ถฉ๋Œํ•˜๋„๋ก ์ถ”๊ฐ€
  ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_PhysicsBody);
}

void URaycast::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
  Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

  Forward = GetForwardVector() * Distance;

  if(GetWorld()->LineTraceSingleByObjectType(HitResult, StartPos, StartPos + Forward, ObjectParams, Params))
  {
    DrawDebugLine(GetWorld(), StartPos, StartPos + Forward, FColor::Green, false, 0.01f, 0, 5.0f);
  }
  else
  {
    DrawDebugLine(GetWorld(), StartPos, StartPos + Forward, FColor::Red, false, 0.01f, 0, 5.0f);
  }
}

3

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๊ณ  Distance ๋ฅผ ์„ค์ •ํ•œ๋‹ค.

2

1

Raycast ๊ฐ€ ObjectType ์„ PhysicsBody ๋กœ ์„ค์ •ํ•œ ํ๋ธŒ์™€ ์ถฉ๋Œํ•˜๋ฉด

์œ„์˜ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด ๋™์ž‘ํ•œ๋‹ค.

์ด์ œ ํšŒ์ „์„ ์ฃผ์–ด ๋ ˆ์ด๋”์™€ ๊ฐ™์ด ์ž‘๋™ํ•˜๋„๋ก ๋งŒ๋“ค์–ด๋ณด์ž.

๐Ÿ“‹ Rotate

1
2
3
public:	
  UPROPERTY(EditAnywhere)
  FRotator RotateVelocity = FRotator(0, 0, 0);

ํ—ค๋”์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถ”๊ฐ€ํ•˜๊ณ 

1
2
3
4
5
6
7
8
9
10
void URaycast::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
  ...

  Rot = GetOwner()->GetActorRotation();
  Rot = Rot + RotateVelocity * DeltaTime;
  GetOwner()->SetActorRotation(Rot);

  ...
}

cpp ํŒŒ์ผ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถ”๊ฐ€ํ•˜๊ณ  ์ž‘๋™์‹œ์ผœ๋ณด์ž.

๐Ÿ’ป ์‹คํ–‰

111

๋ฐฉ๋ฌธํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!๐Ÿ˜Š

์—…๋ฐ์ดํŠธ:

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ