Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void APawnWithPlanetHorizon::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- if (HasAuthority())
- {
- FVector posToPlanet = GetActorLocation() - LocationOfCenterOfGravity;
- posToPlanet.Normalize();
- FRotator rot = UKismetMathLibrary::MakeRotFromZX(posToPlanet, GetActorForwardVector());
- SetActorRotation(rot);
- SetActorLocation((posToPlanet * RadiusOfPlanet) + LocationOfCenterOfGravity);
- VisibleMeshBody->SetPhysicsAngularVelocityInDegrees(FVector(0., 0., 0.));
- VisibleMeshHead->SetPhysicsAngularVelocityInDegrees(FVector(0., 0., 0.));
- VisibleMeshBody->SetPhysicsLinearVelocity(FVector::VectorPlaneProject(VisibleMeshBody->GetPhysicsLinearVelocity(), posToPlanet).GetClampedToMaxSize(maxSpeedOfPawn));
- }
- else if (!IsLocallyControlled())
- {
- VisibleMeshHead->SetRelativeRotation(FRotator(WantedByServerRotOfCharacter.Pitch, 0, 0));
- VisibleMeshHead->SetPhysicsAngularVelocityInDegrees(FVector(0., 0., 0.));
- VisibleMeshBody->SetRelativeRotation(FRotator(0, WantedByServerRotOfCharacter.Yaw, 0));
- VisibleMeshBody->SetPhysicsAngularVelocityInDegrees(FVector(0., 0., 0.));
- }
- }
- void APawnWithPlanetHorizon::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
- {
- Super::SetupPlayerInputComponent(PlayerInputComponent);
- InputComponent->BindAction("MouseLeftClick", IE_Pressed, this, &APawnWithPlanetHorizon::MouseLeftClick);
- InputComponent->BindAxis("MoveForward", this, &APawnWithPlanetHorizon::MoveForwardAxis);
- InputComponent->BindAxis("MoveRight", this, &APawnWithPlanetHorizon::MoveRightAxis);
- InputComponent->BindAxis("RotateX", this, &APawnWithPlanetHorizon::RotateXAxis);
- InputComponent->BindAxis("RotateY", this, &APawnWithPlanetHorizon::RotateYAxis);
- }
- void APawnWithPlanetHorizon::MoveRightAxis(float AxisValue)
- {
- ServerRPC_MoveRightAxis(AxisValue);
- }
- void APawnWithPlanetHorizon::MoveForwardAxis(float AxisValue)
- {
- ServerRPC_MoveForwardAxis(AxisValue);
- }
- void APawnWithPlanetHorizon::RotateXAxis(float AxisValue)
- {
- ServerRPC_RotateXAxis(VisibleMeshBody->GetRelativeRotation().Yaw);
- FRotator rot = VisibleMeshBody->GetRelativeRotation() + FRotator(0, AxisValue, 0);
- VisibleMeshBody->SetRelativeRotation(rot);
- ServerRPC_RotateYAxis(rot.Yaw);
- }
- void APawnWithPlanetHorizon::RotateYAxis(float AxisValue)
- {
- FRotator rot = VisibleMeshHead->GetRelativeRotation() + FRotator(AxisValue, 0, 0);
- if (rot.Pitch > CameraVerticalAngleMax)
- {
- rot.Pitch = CameraVerticalAngleMax;
- }
- else if (rot.Pitch < CameraVerticalAngleMin)
- {
- rot.Pitch = CameraVerticalAngleMin;
- }
- VisibleMeshHead->SetRelativeRotation(rot);
- ServerRPC_RotateYAxis(rot.Pitch);
- }
- void APawnWithPlanetHorizon::ServerRPC_MoveRightAxis_Implementation(float AxisValue)
- {
- if (AxisValue)
- {
- FVector spdToAddTemp = VisibleMeshBody->GetRightVector() * AxisValue;
- float coof = 1;
- if (FVector::DotProduct(MeshMass->GetPhysicsLinearVelocity(), spdToAddTemp) < -3)
- {
- coof = 3;
- }
- MeshMass->SetPhysicsLinearVelocity(spdToAddTemp * 3 * coof, true);
- }
- else
- {
- FVector rightSpd = MeshMass->GetPhysicsLinearVelocity().ProjectOnToNormal(VisibleMeshBody->GetRightVector());
- MeshMass->SetPhysicsLinearVelocity(-rightSpd.GetClampedToMaxSize(2), true);
- }
- }
- void APawnWithPlanetHorizon::ServerRPC_MoveForwardAxis_Implementation(float AxisValue)
- {
- if (AxisValue)
- {
- FVector spdToAddTemp = VisibleMeshBody->GetForwardVector() * AxisValue;
- float coof = 1;
- if (FVector::DotProduct(MeshMass->GetPhysicsLinearVelocity(), spdToAddTemp) < -3)
- {
- coof = 3;
- }
- MeshMass->SetPhysicsLinearVelocity(spdToAddTemp * 3 * coof, true);
- }
- else
- {
- FVector fwdSpd = MeshMass->GetPhysicsLinearVelocity().ProjectOnToNormal(VisibleMeshBody->GetForwardVector());
- MeshMass->SetPhysicsLinearVelocity(- fwdSpd.GetClampedToMaxSize(2), true);
- }
- }
- void APawnWithPlanetHorizon::ServerRPC_RotateXAxis_Implementation(float WantedAngleCameraX)
- {
- VisibleMeshBody->SetRelativeRotation(FRotator(0, WantedAngleCameraX, 0));
- WantedByServerRotOfCharacter.Yaw = WantedAngleCameraX;
- }
- void APawnWithPlanetHorizon::ServerRPC_RotateYAxis_Implementation(float WantedAngleCameraY)
- {
- VisibleMeshHead->SetRelativeRotation(FRotator(WantedAngleCameraY, 0, 0));
- WantedByServerRotOfCharacter.Pitch = WantedAngleCameraY;
- }
Advertisement
Add Comment
Please, Sign In to add comment