BahamutoD / BDArmory

Gun turrets and other weapon systems for KSP
38 stars 112 forks source link

BDA collision detection currently has the same issue as an older version of KSP, fix inside: #56

Open allmhuran opened 7 years ago

allmhuran commented 7 years ago

Reference this thread on the KSP forum from about a year ago http://forum.kerbalspaceprogram.com/index.php?/topic/121017-thermal-mechanics-and-physicssignificance/#comment-2478242

I can't remember which version of KSP it was at the time, but NK confirmed in that thread that when raycasts were used by engine exhaust to determine where heat should be applied, it was being applied to the wrong part if the actual "hit" part was physicsless.

BD Armory currently suffers exactly the same problem.

The issue is in pooledBullet.cs on line 254, specifically:

hitPart = Part.FromGO(hit.rigidbody.gameObject);

This causes a walk up the part tree to the first "physics" part.

However, the solution is to do exactly as NathanKell indicated in that forum thread... return the first actual part instead. And happily. code to do this correctly is also found in another file in BD Armory. The ModuleWeapon.cs implementation for lasers at line 1242 works as expected: if the laser actually hits a physicsless part then the following code correctly returns it:

Part p = hit.collider.gameObject.GetComponentInParent<Part>();

I have recompiled BD Armory on my machine, with the following single line change, which corrects the error. In pooledBullet.cs at line 254, remove

hitPart = Part.FromGO(hit.rigidbody.gameObject);

and replace it with

hitPart = hit.collider.gameObject.GetComponentInParent<Part>();

allmhuran commented 7 years ago

I should add: This will apply heat to the correct part, even if it is physicsless.

However, explosive weapons will also want to impart a force. No doubt this aspect of the code will want the actual physics part.

So I suggest using the hitPart = hit.collider.gameObject.GetComponentInParent<Part>(); code to determine where to apply heat, but the Part.FromGO(hit.rigidbody.gameObject); in order to determine where to apply force. Or, alternatively, simply apply heat to physicsless parts, but ignore force rather than pushing on the physics parent.

Specifically, this refers to lines 115 to 149 in explosionFX.cs. Right now, both heat and force require that the part have physics. However, it seems like the code could instead apply heat to parts regardless of physics, and force only if they have physics.

I can probably figure out how to make pull requests for each of these changes if you'd like. They're both really simple, and neither has any far-reaching consequences outside of the functions in which the change would be made.

boomchacle commented 7 years ago

Kinda off topic, but I think that BD's armory's explosion physics have an infinite amount of force. if you have many small objects with the same surface area of a larger one, they will be blown up with more force.