Hello,
I have an issue that I can’t fix. I have a 3D ball which I move by applying forces.
The problem is the camera. I can’t make it following the ball without rotating.
void Sample::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
{
Node* ballNode = objectNode;
const float CAMERA_MIN_DIST = 1.0f;
const float CAMERA_INITIAL_DIST = 5.0f;
const float CAMERA_MAX_DIST = 20.0f;
Quaternion dir(ballNode->GetRotation().YawAngle(), Vector3::UP);
dir = dir * Quaternion(yaw_, Vector3::UP);
dir = dir * Quaternion(pitch_, Vector3::RIGHT);
Quaternion rot = ballNode->GetRotation();
Vector3 cameraTargetPos = ballNode->GetPosition() -dir * Vector3(0.0f, 0.0f, 10.f);
Vector3 cameraStartPos = ballNode->GetPosition();
Ray cameraRay(cameraStartPos, cameraTargetPos - cameraStartPos);
float cameraRayLength = (cameraTargetPos - cameraStartPos).Length();
PhysicsRaycastResult result;
scene_->GetComponent<PhysicsWorld>()->RaycastSingle(result, cameraRay, cameraRayLength, 2);
if (result.body_)
cameraTargetPos = cameraStartPos + cameraRay.direction_ * (result.distance_ - 0.5f);
cameraNode_->SetPosition(cameraTargetPos);
cameraNode_->SetRotation(dir);
}
Controls seems also inverted.
yaw_ and pitch_ are related to the camera.
Trying to get something similar to this:
youtube.com/watch?v=KAgIJcHNE4s