fix: inverted direction of normal influence on camera distance
This commit is contained in:
parent
3102375f99
commit
b43241da4f
2 changed files with 9 additions and 4 deletions
|
|
@ -16,7 +16,7 @@ void PlayerCamera::_bind_methods() {
|
|||
|
||||
void PlayerCamera::update_rotation() {
|
||||
double const delta{ get_process_delta_time() };
|
||||
Vector3 velocity{ get_parent_node_3d()->get_global_position() - this->previous_origin };
|
||||
Vector3 velocity{ get_origin() - this->previous_origin };
|
||||
if (velocity.length() > 0.1 && this->mouse_look_input.is_zero_approx() && this->joystick_input.is_zero_approx()) {
|
||||
Vector3 forward{ -get_global_basis().get_column(2) };
|
||||
forward.y = 0;
|
||||
|
|
@ -42,7 +42,7 @@ void PlayerCamera::update_rotation() {
|
|||
}
|
||||
|
||||
void PlayerCamera::update_position() {
|
||||
Vector3 origin{ get_parent_node_3d()->get_global_position() };
|
||||
Vector3 origin{ get_origin() };
|
||||
Vector3 direction{ get_global_basis().get_column(2) };
|
||||
float distance{ this->target_distance };
|
||||
Vector3 target{ origin + direction * distance };
|
||||
|
|
@ -50,11 +50,11 @@ void PlayerCamera::update_position() {
|
|||
this->ray.to = target;
|
||||
PhysicsDirectSpaceState3D::RayResult result{};
|
||||
if (get_world_3d()->get_direct_space_state()->intersect_ray(this->ray, result)) {
|
||||
distance = origin.distance_to(result.position) - Math::abs(direction.dot(result.normal));
|
||||
distance = origin.distance_to(result.position) - (2.0 - Math::abs(direction.dot(result.normal)));
|
||||
} else {
|
||||
distance -= 1.f;
|
||||
}
|
||||
look_at_from_position(origin + direction * MAX(distance, 0.5f), origin);
|
||||
look_at_from_position(origin + direction * MAX(distance, 0.4f), origin);
|
||||
this->previous_origin = origin;
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +93,10 @@ void PlayerCamera::unhandled_input(Ref<InputEvent> const &event) {
|
|||
}
|
||||
}
|
||||
|
||||
Vector3 PlayerCamera::get_origin() const {
|
||||
return get_parent_node_3d()->get_global_position() + Vector3::UP * 0.25f;
|
||||
}
|
||||
|
||||
void PlayerCamera::set_blocking_mask(uint32_t mask) {
|
||||
this->ray.collision_mask = mask;
|
||||
notify_property_list_changed();
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ private:
|
|||
};
|
||||
|
||||
public:
|
||||
Vector3 get_origin() const;
|
||||
GET_SET_FNS(float, target_distance);
|
||||
GET_SET_FNS(float, mouse_sensitivity);
|
||||
GET_SET_FNS(float, joystick_sensitivity);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue