ABOUT ME

Today
Yesterday
Total
  • 문 물리 작용 업데이트
    Game Programming/언리얼 2023. 10. 19. 12:51

    이전 포스팅을 참조하자면 타이머 안에서 문의 위치를 1씩 움직이는 방법으로 구현했다.

    https://korean-paul.tistory.com/102

     

    Create Door

    cpp클래스에 Item 클래스를 상속받는 ACDoor 클래스를 선언했다. CDoor.h protected: virtual void BeginPlay() override; virtual void OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp

    korean-paul.tistory.com

    
    LeftDoorComponent->SetSimulatePhysics(true);
    LeftDoorComponent->SetEnableGravity(false);
    LeftDoorComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
    LeftDoorComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
    
    RightDoorComponent->SetSimulatePhysics(true);
    RightDoorComponent->SetEnableGravity(false);
    RightDoorComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
    RightDoorComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);

    수정한 void ACDoor::OpencloseDoor() 함수의 일부이다. 

    LeftDoorComponent->SetSimulatePhysics(true);
    LeftDoorComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);

    문의 물리 기능을 켰다.

    LeftDoorComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);

    충돌 기능은 껏다.

     

    물리 설정에 대해 이해하기 위해 아래와 같이 실험을 진행해봤다.

     

    왼쪽문 SetSimulatePhysics(false);
    SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);

    오른쪽 문 SetSimulatePhysics(true);
    SetCollisionEnabled(ECollisionEnabled::NoCollision);

    결과

    언리얼 경고 메시지

     

    결국에는 SetSimulatePhysics, SetCollisionEnabled이 올바르게 설정이 되고 물리 함수를 호출해야한다.

     

    void ACDoor::DoorOpenCloseFunc()
    {
    	LeftDoorComponent->SetSimulatePhysics(false);
    	LeftDoorComponent->SetEnableGravity(false);
    	LeftDoorComponent->SetVisibility(true);
    	LeftDoorComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
    	LeftDoorComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
    
    	RightDoorComponent->SetSimulatePhysics(false);
    	RightDoorComponent->SetEnableGravity(false);
    	RightDoorComponent->SetVisibility(true);
    	RightDoorComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
    	RightDoorComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
    
    	bDoorTimerActive = false;
    }

    문을 동작시키고 타이머가 완료되면 물리 기능은 끄도록 구현했다.

    'Game Programming > 언리얼' 카테고리의 다른 글

    Create Door Trigger  (1) 2023.10.20
    문 소켓 추가  (0) 2023.10.19
    무기 교체  (0) 2023.10.18
    무기 버리는 물리효과 추가  (1) 2023.10.18
    Item Falling State  (0) 2023.10.17
Designed by Tistory.