protected override void ReceiveTick_Implementation(float DeltaSeconds) { base.ReceiveTick_Implementation(DeltaSeconds); // Determine which Puzzle Block the player is looking at and highlight it. if (UHeadMountedDisplayFunctionLibrary.IsHeadMountedDisplayEnabled()) { UCameraComponent camera = VrCamera; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); FVector start = camera.GetWorldLocation(); FVector end = start + (camera.GetWorldRotation().GetForwardVector() * 8000); FHitResult hitResult; bool hit = USystemLibrary.LineTraceSingle(this, start, end, UEngineTypes.ConvertToTraceType(ECollisionChannel.Camera), false, null, EDrawDebugTrace.None, out hitResult, true, FLinearColor.Red, FLinearColor.Green, 0); APuzzleBlock block = hit ? hitResult.Actor.Value as APuzzleBlock : null; if (block != null) { CurrenBlockFocus = block; block.DoHighlight(true); } else if (CurrenBlockFocus != null) { CurrenBlockFocus.DoHighlight(false); CurrenBlockFocus = null; } } }
public override void Initialize(FObjectInitializer initializer) { base.Initialize(initializer); VrCamera = initializer.CreateDefaultSubobject <UCameraComponent>(this, new FName("VR_Camera")); VrCamera.RelativeLocation = new FVector(-100, 0, 270); VrCamera.AutoActivate = false; VrCamera.AttachToComponent(CapsuleComponent, FName.None, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, false); FpCamera = initializer.CreateDefaultSubobject <UCameraComponent>(this, new FName("FP_Camera")); FpCamera.RelativeLocation = new FVector(600, 0, 230); FpCamera.RelativeRotation = new FRotator(-89.9000015f, -1.5f, 1.5f); FpCamera.AutoActivate = false; FpCamera.AttachToComponent(CapsuleComponent, FName.None, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, false); CharacterMovement.GravityScale = 0; UseControllerRotationYaw = false; // Enable tick FTickFunction tickFunction = PrimaryActorTick; tickFunction.StartWithTickEnabled = true; tickFunction.CanEverTick = true; }