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

PhysicsDirectSpaceState2D get_rest_info returned dictionary should also contain a field for the actual collision object #49591

Open
Tracked by #45334
SoloByte opened this issue Jun 14, 2021 · 2 comments

Comments

@SoloByte
Copy link

SoloByte commented Jun 14, 2021

Godot version

3.3.2

System information

Windows 10

Issue description

Currently, the get_rest_info method in Physics2DDirectSpaceState returns a dictionary containing the following fields:

  • collider_id: The colliding object's ID.
  • linear_velocity: The colliding object's velocity Vector2.
  • metadata: The intersecting shape's metadata
  • normal: The object's surface normal at the intersection point.
  • point: The intersection point.
  • rid: The intersecting object's RID.
  • shape: The shape index of the colliding shape.

The problem is I cannot get the actual collision object from this information. (As far as I know) Both the "collider_id" and "RID" can´t be used anywhere to retrieve the actual object. The instance_from_id function solves my current problem. Although I still think it would be nice to have a collider field in the dictionary or mention the "instance_from_id" function in the documentation for get_rest_info.

The intersect_point, intersect_ray and intersect_shape functions all return a collider (the actual object I am looking for) but get_rest_info does not.

I want to use get_rest_info in combination with cast_motion for a custom projectile system. Without the actual collider object, there is no point for me to use this function. (A projectile needs to interact with the object it collided with for applying damage etc. ) So currently I am using the collide_shape function (returns an array of collision points) with the intersect_ray function to get the results I need.

By looking at the class (Line: 481) responsible for those functions it looks like it should be very easy to add a collider field to the returned dictionary.

An alternative solution to my problem would be to add a function to the Physics2DServer to get the actual object from a RID or the collider_id.

I did not know if I should open a feature proposal or a bug report for this. If it's in the wrong place here I am happy to open a feature proposal instead.

Steps to reproduce

There are no steps to reproduce.

Minimal reproduction project

No response

@ICatRegister
Copy link

var collider = instance_from_id(collider_id)

@SoloByte
Copy link
Author

@ICatRegister Thank you very much :) It works.

I found it. It is global function in GDScript for anyone having the same issue.

I think it still would be nice to have to collider field in the returned dictionary or at least mention the "instance_from_id" function in the documentation.

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

3 participants