Elvince
(Elvince)
July 25, 2014, 9:25am
1
Hi,
I’m trying to understand how the arms are following the crosshair movement in ShooterGame.
I want to implement the same functionality, but I can’t get where the value are set for the Arms.
I catch for the ThirdPerson mesh but can’t get it for the FirstPerson.
Thanks,
The crosshair in shootergame is drawn in the center of the screen.
The movement of the players view is controlled by adding pitch to the player controller.
Elvince
(Elvince)
July 25, 2014, 11:49am
3
This was not what I’m looking for. I wanted to know how the Arms were following the mouse movement.
And I found it, it’s in CameraUpdate on Character class.
thanks,
Could you explain the method you used in some detail?
That be awsome.
Odd, I would like to know more too. I just made my own arms children of the Camera and everything worked fine
Elvince
(Elvince)
July 25, 2014, 3:25pm
6
Just look in ShooterGame code in the CharacterClass::OnCameraUpdate(const FVector& CameraLocation, const FRotator& CameraRotation)
They are using the camera location & rotation to place & rotate the arms correctly.
USkeletalMeshComponent* DefMesh1P = Cast<USkeletalMeshComponent>(GetClass()->GetDefaultSubobjectByName(TEXT("PawnMesh1P")));
const FMatrix DefMeshLS = FRotationTranslationMatrix(DefMesh1P->RelativeRotation, DefMesh1P->RelativeLocation);
const FMatrix LocalToWorld = ActorToWorld().ToMatrixWithScale();
// Mesh rotating code expect uniform scale in LocalToWorld matrix
const FRotator RotCameraPitch(CameraRotation.Pitch, 0.0f, 0.0f);
const FRotator RotCameraYaw(0.0f, CameraRotation.Yaw, 0.0f);
const FMatrix LeveledCameraLS = FRotationTranslationMatrix(RotCameraYaw, CameraLocation) * LocalToWorld.InverseSafe();
const FMatrix PitchedCameraLS = FRotationMatrix(RotCameraPitch) * LeveledCameraLS;
const FMatrix MeshRelativeToCamera = DefMeshLS * LeveledCameraLS.InverseSafe();
const FMatrix PitchedMesh = MeshRelativeToCamera * PitchedCameraLS;
Mesh1P->SetRelativeLocationAndRotation(PitchedMesh.GetOrigin(), PitchedMesh.Rotator());
Thanks i will have a look at the shooter example as well.
Thanks for the share.
Also, if your weapon class contains your arms, and it is simply extended from actor, you can set the rotation from the Character’s tick function:
void MyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
Weapon->SetActorLocation(GetPawnViewLocation());
Weapon->SetActorRotation(GetViewRotation());
}