Jump to content

physics.raycasts and physicsSignificance


allmhuran

Recommended Posts

Hey all, I'm trying to decipher the behaviour of a mod by peeking at the source code.

The code in question is as follows, from BD Armory:

 

 Ray ray = new Ray(prevPosition, currPosition - prevPosition);
  RaycastHit hit;
  if (Physics.Raycast(ray, out hit, dist, 557057))
  {
      bool penetrated = true;
      Part hitPart = null;   //determine when bullet collides with a target
      try
      {
          hitPart = Part.FromGO(hit.rigidbody.gameObject);
      }
      catch (NullReferenceException)
      {
      }
	// ...


What I'm curious about is what is happening when the ray hits a part with physicsSignificance = 1.

I know that the raycast "hits" the physicsless part in some way, because the mod shows a graphical impact effect at the point where it hits on the surface of that physicsless part. However, the effects of the "hit", namely the application of heat, seem to be applied further up the part tree. More specifically, to the first part in the tree that is not physicsless.

Is that correct? Do raycasts (or perhaps calls to get a rigidBody.gameObject) traverse up the part tree until finding the first part with normal physics, or have I misinterpreted that? Perhaps this relates to an issue I found regarding physicsless parts and engine exhaust heat some time ago.

Further, if it is expected that the raycast does return the first normal-physics part, then is there a way to return the part that was actually hit (ie, the physicless part) rather than walking up the tree?





 

Edited by allmhuran
Link to comment
Share on other sites

Solved with lots more investigation: Using rigidBody.gameObject forces a walk up the tree, since the physicsless part has no rigidBody (or rather, setting this flag causes the rigidBody to be ignored or removed at runtime). 

To return the actual physicless part, use the collider instead.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...