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

Return collided object for VehicleWheel #3640

Closed
rydergaming opened this issue Dec 7, 2021 · 7 comments
Closed

Return collided object for VehicleWheel #3640

rydergaming opened this issue Dec 7, 2021 · 7 comments

Comments

@rydergaming
Copy link

rydergaming commented Dec 7, 2021

Describe the project you are working on

I am working on a 3D racing game using the built in VehicleBody and VehicleWheel classes.

Describe the problem or limitation you are having in your project

I cannot get what the VehicleWheel is in contact with form the wheel itself.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

While I can check if a collision is happening with VehicleWheel's is_in_contact(), I can not get what the wheel is actually colliding with.

By adding a new method we could return what object the wheel is colliding with.

A common use case for this would be to check if the wheel is on tarmac, dirt, grass, etc. and we could update it's wheel_friction_slip accordingly.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I can see two solutions for this:

  • Update the is_in_contact() to return either null or the object the collision is happening with.
  • Create a new method that returns null or the object the collision is happening with.

I have limited C++ knowledge, but it seems to me returning wheel.m_raycastInfo.m_groundObject would solve this.

This is a piece of real_t VehicleBody3D::_ray_cast(int p_idx, PhysicsDirectBodyState3D *s) from scene/3d/vehicle_body_3d.cpp

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

	wheel.m_raycastInfo.m_groundObject = nullptr;

	if (col) {
		param = source.distance_to(rr.position) / source.distance_to(target);
		depth = raylen * param;
		wheel.m_raycastInfo.m_contactNormalWS = rr.normal;

		wheel.m_raycastInfo.m_isInContact = true;
		if (rr.collider) {
			wheel.m_raycastInfo.m_groundObject = Object::cast_to<PhysicsBody3D>(rr.collider);
		}

If this enhancement will not be used often, can it be worked around with a few lines of script?

A workaround could be achieved with adding a RayCast to each wheel manually, but it seems redundant if there's one already in the VehicleWheel class.

Is there a reason why this should be core and not an add-on in the asset library?

As the VehicleWheel is already in core it makes sense to add this improvement to core as well.

@rydergaming
Copy link
Author

I would be happy to implement this improvement to flex my C++ muscles if it gets accepted as something that's needed.

@pouleyKetchoupp
Copy link

pouleyKetchoupp commented Dec 7, 2021

Yeah, that sounds like a good idea! A PR would be welcome.

I would go for adding a new method called get_contact_body() that returns a Node, so it will be more flexible for later if we want to support both PhysicsBody3D and GridMap.

See the body entered signal on rigid bodies as a reference for documentation:
https://github.com/godotengine/godot/blob/46d384060ef20672e23b3c1ffe947ff7898ecf75/doc/classes/RigidDynamicBody3D.xml#L169-L175

@rydergaming
Copy link
Author

Great! I will get on it and hopefully I'll have something in the following days!

@arjun988
Copy link

arjun988 commented Dec 8, 2021

hi I am arjun , I am having intermediate knowledge in C++ pls tell me what should I learn so that I can contribute . it would be very helpful if u can guide me.

@rydergaming
Copy link
Author

I successfully implemented this feature and sent in a PR here.

@pouleyKetchoupp
Copy link

hi I am arjun , I am having intermediate knowledge in C++ pls tell me what should I learn so that I can contribute . it would be very helpful if u can guide me.

Hi Arjun! You can read this article about contributing to the code. I would suggest to start with checking issues from the main repo with the junior job label to get familiar with the engine.

@akien-mga akien-mga added this to the 4.0 milestone Dec 10, 2021
@akien-mga
Copy link
Member

Implemented by godotengine/godot#55723.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants