Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VehicleWheel can now return the surface it's colliding with. #55723

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/classes/VehicleWheel3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
<link title="3D Truck Town Demo">https://godotengine.org/asset-library/asset/524</link>
</tutorials>
<methods>
<method name="get_contact_body" qualifiers="const">
<return type="Node3D" />
<description>
Returns the contacting body node if valid in the tree, as [Node3D]. At the moment, [GridMap] is not supported so the node will be always of type [PhysicsBody3D].
Returns [code]null[/code] if the wheel is not in contact with a surface, or the contact body is not a [PhysicsBody3D].
</description>
</method>
<method name="get_rpm" qualifiers="const">
<return type="float" />
<description>
Expand Down
8 changes: 6 additions & 2 deletions scene/3d/vehicle_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ bool VehicleWheel3D::is_in_contact() const {
return m_raycastInfo.m_isInContact;
}

Node3D *VehicleWheel3D::get_contact_body() const {
return m_raycastInfo.m_groundObject;
}

void VehicleWheel3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_radius", "length"), &VehicleWheel3D::set_radius);
ClassDB::bind_method(D_METHOD("get_radius"), &VehicleWheel3D::get_radius);
Expand Down Expand Up @@ -257,6 +261,7 @@ void VehicleWheel3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_friction_slip"), &VehicleWheel3D::get_friction_slip);

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("set_roll_influence", "roll_influence"), &VehicleWheel3D::set_roll_influence);
ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel3D::get_roll_influence);
Expand Down Expand Up @@ -413,9 +418,8 @@ real_t VehicleBody3D::_ray_cast(int p_idx, PhysicsDirectBodyState3D *s) {
ray_params.exclude = exclude;
ray_params.collision_mask = get_collision_mask();

bool col = ss->intersect_ray(ray_params, rr);

wheel.m_raycastInfo.m_groundObject = nullptr;
bool col = ss->intersect_ray(ray_params, rr);

if (col) {
param = source.distance_to(rr.position) / source.distance_to(target);
Expand Down
2 changes: 2 additions & 0 deletions scene/3d/vehicle_body_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class VehicleWheel3D : public Node3D {

bool is_in_contact() const;

Node3D *get_contact_body() const;

void set_roll_influence(real_t p_value);
real_t get_roll_influence() const;

Expand Down