소스 검색

Merge pull request #93900 from TestSubject06/10106/raycast_info_on_wheels

Expose contact point and contact normal on VehicleWheel3D to scripting.
Rémi Verschelde 1 년 전
부모
커밋
9725c03228
3개의 변경된 파일26개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      doc/classes/VehicleWheel3D.xml
  2. 10 0
      scene/3d/physics/vehicle_body_3d.cpp
  3. 4 0
      scene/3d/physics/vehicle_body_3d.h

+ 12 - 0
doc/classes/VehicleWheel3D.xml

@@ -18,6 +18,18 @@
 				Returns [code]null[/code] if the wheel is not in contact with a surface, or the contact body is not a [PhysicsBody3D].
 				Returns [code]null[/code] if the wheel is not in contact with a surface, or the contact body is not a [PhysicsBody3D].
 			</description>
 			</description>
 		</method>
 		</method>
+		<method name="get_contact_normal" qualifiers="const">
+			<return type="Vector3" />
+			<description>
+				Returns the normal of the suspension's collision in world space if the wheel is in contact. If the wheel isn't in contact with anything, returns a vector pointing directly along the suspension axis toward the vehicle in world space.
+			</description>
+		</method>
+		<method name="get_contact_point" qualifiers="const">
+			<return type="Vector3" />
+			<description>
+				Returns the point of the suspension's collision in world space if the wheel is in contact. If the wheel isn't in contact with anything, returns the maximum point of the wheel's ray cast in world space, which is defined by [code]wheel_rest_length + wheel_radius[/code].
+			</description>
+		</method>
 		<method name="get_rpm" qualifiers="const">
 		<method name="get_rpm" qualifiers="const">
 			<return type="float" />
 			<return type="float" />
 			<description>
 			<description>

+ 10 - 0
scene/3d/physics/vehicle_body_3d.cpp

@@ -219,6 +219,14 @@ bool VehicleWheel3D::is_in_contact() const {
 	return m_raycastInfo.m_isInContact;
 	return m_raycastInfo.m_isInContact;
 }
 }
 
 
+Vector3 VehicleWheel3D::get_contact_point() const {
+	return m_raycastInfo.m_contactPointWS;
+}
+
+Vector3 VehicleWheel3D::get_contact_normal() const {
+	return m_raycastInfo.m_contactNormalWS;
+}
+
 Node3D *VehicleWheel3D::get_contact_body() const {
 Node3D *VehicleWheel3D::get_contact_body() const {
 	return m_raycastInfo.m_groundObject;
 	return m_raycastInfo.m_groundObject;
 }
 }
@@ -256,6 +264,8 @@ void VehicleWheel3D::_bind_methods() {
 
 
 	ClassDB::bind_method(D_METHOD("is_in_contact"), &VehicleWheel3D::is_in_contact);
 	ClassDB::bind_method(D_METHOD("is_in_contact"), &VehicleWheel3D::is_in_contact);
 	ClassDB::bind_method(D_METHOD("get_contact_body"), &VehicleWheel3D::get_contact_body);
 	ClassDB::bind_method(D_METHOD("get_contact_body"), &VehicleWheel3D::get_contact_body);
+	ClassDB::bind_method(D_METHOD("get_contact_point"), &VehicleWheel3D::get_contact_point);
+	ClassDB::bind_method(D_METHOD("get_contact_normal"), &VehicleWheel3D::get_contact_normal);
 
 
 	ClassDB::bind_method(D_METHOD("set_roll_influence", "roll_influence"), &VehicleWheel3D::set_roll_influence);
 	ClassDB::bind_method(D_METHOD("set_roll_influence", "roll_influence"), &VehicleWheel3D::set_roll_influence);
 	ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel3D::get_roll_influence);
 	ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel3D::get_roll_influence);

+ 4 - 0
scene/3d/physics/vehicle_body_3d.h

@@ -130,6 +130,10 @@ public:
 
 
 	bool is_in_contact() const;
 	bool is_in_contact() const;
 
 
+	Vector3 get_contact_point() const;
+
+	Vector3 get_contact_normal() const;
+
 	Node3D *get_contact_body() const;
 	Node3D *get_contact_body() const;
 
 
 	void set_roll_influence(real_t p_value);
 	void set_roll_influence(real_t p_value);