Aoredon
(Aoredon)
July 31, 2015, 12:12am
3
I’m having a hard time understanding exactly what your problem is on issue 1. Are you saying you are getting a crash or a that you are getting unreliable behavior? I believe you are right about gimbal lock. You are also right about using quaternions to fix it, but it’s hard to see what’s going wrong with your description.
Issue 2: The hiearchy should prevent moving the behavior you are describing. Moving the spring arm should not move what the camera is attached to. I THINK. I’m not an expert on this. But you should be able to move the camera by adjusting the spring arm values: TargetArmLength, RelativeRotation, etc.
Issue 3: You could try and use this value on your spring arm: SpringArmComponent->CameraLagSpeed = 3.0f;
Issue 4: If I remember correctly freelancer’s ship just always tried to steer towards the direction of the mouse. Maybe you could try to work in screen space. Get the screen position of the ship, get the screen position of the mouse, and then apply impulses or whatever, or order to steer the ship in the direction of the mouse. If you look at the video, the ship always stays in the middle of the screen and it maintains a constant turn rate depending on the distance of the mouse from the screen (The further the mouse from center, the faster the turn).
Hope that helps.
Your post was very helpful thank you. The only real issue I have is that I need the ship to rotate to face the mouse cursor. If I use quaternions it’s fine unless I’m using it combined with the mouse position.
This is my current code:
ASpaceGamePlayerController* PlayerController = (ASpaceGamePlayerController*) GetWorld()->GetFirstPlayerController();
FTransform Transform;
FRotator Rotation;
FVector MouseLocation;
FVector MouseDirection;
PlayerController->DeprojectMousePositionToWorld(MouseLocation, MouseDirection);
Rotation = MouseDirection.Rotation();
Transform = this->GetTransform();
Transform.SetRotation(Rotation.Quaternion());
Transform.NormalizeRotation();
this->SetActorTransform(Transform);
(I was messing around with stuff so that’s kind of rough. Before I had interpolation.)
To be honest if I could find a method that can apply some sort of force to rotate the object that would be even better. I could just make it apply that force until the ship aligns with the cursor.