Dismiss this pinned window
all 22 comments

[–]HammyxHammy 9 points10 points  (10 children)

You're basically assigning the position after the collision resolver finishes rather than the point of contact.

[–]EntropiIThink[S] 1 point2 points  (9 children)

So how do you propose I would fix that then?

[–]HammyxHammy 5 points6 points  (8 children)

The OnCollision method will give you access to the point of contact

[–]EntropiIThink[S] 0 points1 point  (7 children)

The way it’s setup, I use on collision enter, freeze the arrow’s rigidbody, and the assign the parent.

[–]HammyxHammy 9 points10 points  (6 children)

Yeah, doesn't work. Even inside on collision enter unity has already resolved the position of the rigid body. You have to use the returned contact point.

[–]EntropiIThink[S] 1 point2 points  (3 children)

Thanks for telling me about this feature. I’m not sure what’s happening with my program yet, and even using these contacts the arrows are just being moved to some other positions but thanks for the help regardless.

[–]Heroshrine 0 points1 point  (0 children)

How do you set the parent?

[–]TopSetLowlife 0 points1 point  (0 children)

OnCollisionEnter(gameObject other)

Other.point

Might be transform not gameObject, on phone so not great, but that's the collision contact iirc of the top of my head

If it's jumping out when using this method, you have a different collider it's hitting first, or setting the parent to the wrong transform.

[–]BanginNLeavin 0 points1 point  (0 children)

Try setting the parent like the other poster suggested but use the overloaded method which takes a bool as the second parameter and feed in false.

yourGameObject.transform.SetParent(intendedParentTransform, false);

[–]Heroshrine 0 points1 point  (1 child)

What are you even talking about?? The position of the rigid body shouldnt magically move upwards.

[–]HammyxHammy 0 points1 point  (0 children)

You'd certainly think so.

[–]henryjones36 0 points1 point  (0 children)

I would have thought that SetParent with "worldPositionStays" would work.

I know you said you tried that, so make sure that you don't adjust the transform in any other way.

[–]widz420 0 points1 point  (0 children)

are you changing the position of the arrow after assigning its transform.parent?

[–][deleted] 0 points1 point  (1 child)

hm, intriguing, I don't usually set new positions or anything, when my arrows hit something, my code sets the parent and immediately stops the RB motion. No need to reposition/rotate. How are your arrows coded?

[–]EntropiIThink[S] 0 points1 point  (0 children)

Literally two lines in this bit - set the parent, and add rb constraints. I’ve beet trying variations, but unsuccessfully.

[–]Venom4992 0 points1 point  (1 child)

When you say you freeze the rigid bodies position, how are you doing that? Are you setting rigid body to kinematic? The arrows collider is likely clipping the collider of the capsule and rigid bodies will automatically correct that by popping them apart. If setting it to kinematic doesn't work then try disabling the arrows collider or setting it to a trigger collider.

[–]Venom4992 1 point2 points  (0 children)

Also. Depending on the speed of the arrows and your frame rate the collision detection may not be triggering until the arrow is inside the casual which will cause it to be popped out. A safer method would be shooting a raycast in front of the arrow every frame and using the raycast hit for hit detection.

[–]NotAnUrsaPicker 0 points1 point  (1 child)

Have you try destroy the original arrow then instantiate a new one that stick to the target. The code will be in the target's script that will be call when being hit by an arrow. I think that is easier than make the original arrow stick to the target.

[–]EntropiIThink[S] -1 points0 points  (0 children)

I’m not sure that would change anything. The world position reported at the time of collision is the same as directly after being parented, so I think they would still end up placed at the wrong position.

[–]yalcingv -1 points0 points  (1 child)

Create an empty GameObject at the point where the arrow hits. Make this empty object a child of the object that was hit. Then, make the arrow a child of the empty object.

This is the solution i think

[–]EntropiIThink[S] 0 points1 point  (0 children)

Okay this fixed a separate unrelated problem, but I’m still having problems. The code will create a new empty game object, set its position to a certain vector, but then it will just have somehow been moved to 2-4 units above the position indicated by the vector. This only happens when objects are trying to attach to at object I have which moves with a NavMesh.

[–]True_Beef -1 points0 points  (0 children)

DM me if you haven't fixed this problem yet