#How would I go about giving a joint collision?

1 messages · Page 1 of 1 (latest)

royal umbra
#

I currently have a setup where there are solid nodes that are connected by relative joints. My previous solution for giving the joints collision was to just have an object with an edge collider that gets stretched to fill the space between them, but this doesn't transfer any force when something colliders with it. I tried to use something like this on the collider,

⁨⁨⁨⁨```C#
public void OnCollisionEnter2D(Collision2D collision){
node1.AddForceAtPosition(collision.relativeVelocitycollision.otherRigidbody.mass, collision.transform.position, ForceMode2D.Force);
node2.AddForceAtPosition(collision.relativeVelocity
collision.otherRigidbody.mass, collision.transform.position, ForceMode2D.Force);
}
public void OnCollisionStay2D(Collision2D collision){
node1.AddForceAtPosition(collision.relativeVelocitycollision.otherRigidbody.mass, collision.transform.position, ForceMode2D.Force);
node2.AddForceAtPosition(collision.relativeVelocity
collision.otherRigidbody.mass, collision.transform.position, ForceMode2D.Force);
}



but the objects mostly just bounce off it instead of "pushing" the structure down because from the object's POV, the connection collider is not truly dynamic, its just being teleported into place to stretch across the gap. Is there any good way to give the joint collision and have its interactions affect the nodes?
frail spade
#

How would I go about giving a joint collision?
You wouldn't. Only Rigidbodies and static colliders can have collision
was to just have an object with an edge collider that gets stretched to fill the space between them
Between what? You mean the two Rigidbodies attached by the joint? Which Rigidbody does the collider belong to?
but this doesn't transfer any force when something colliders with it
Again which Rigidbody was the collider associated with?

An edge collider wouldn't be ideal for this either - a capsule collider would be better.

royal umbra
#

Yes, between the two nodes.
The connection object itself has its own collider.
I imagine this (edge with a radius above 0) is the same as a capsule, right?

frail spade
#

not really

#

edge colliders don't have an "inside"

#

capsule colliders do

royal umbra
#

interesting, I'll switch it over

#

do you think the approach I shared has any chance of working?

#

with some tweaks

frail spade
#

You haven't really answered the main question I had about the structure of all this

#

Rigidbodies are the main unit of "thing" in the physics engine

royal umbra
#

yeah, there are 3 involved here

#

2 nodes, and the connection

frail spade
#

I think what you need to actually do here to make this realistically work is to make that connection object have very low mass (like 0.0001 or whatever), and then have its own separate two joints connecting it to the connection points

#

although... the stretching bit may still cause problems

royal umbra
#

to keep the same behavior of their connection

frail spade
#

yes

royal umbra
#

at 0.0001 they just have 0 collision

#

any idea why that would happen?

#

just to clarify exactly what I did, I kept everything the same but added 2 hinge joints on either side of the connection object that connect to the nodes

#

and here's the exact stretch code since that might be relevant

royal umbra
#

I still haven't had any luck making things work

#

tried fixed joints and distance joints but both are way too unstable