I want to fly bullets, and I want to realize the movement of the bullets that hit each other stick together.

Asked 2 years ago, Updated 2 years ago, 97 views

Let me ask you a question where the Unity 4 introduction is full.
I skipped the chicken object as a bullet and entered the Java code in C# that says if the bullets hit each other, they would stick together, but just when the bullets hit each other, they would play and fall off normally.

Fab the chicken bullet, add this script, and enter 70,120 for force and torque in public.
As a result of debugging in Print to verify that the hit was successful and that the data was substituted for the component, the value set to 70,120 was successfully displayed.
I wonder if the CharacterJoint has not been made yet, but it will fall apart.What should I do?

using System.Collections;
using System.Collections.General;
using UnityEngine;

public class StickBall —MonoBehavior
{
    public float force;
    public float torque;
    private CharacterJoint myjoin;
    public void OnCollisionEnter (Collision other)
    {

        if(other.gameObject.tag=="Bullet")
        {
            if(myjoint==null)
            {
                myjoint=gameObject.AddComponent<CharacterJoint>();
                myjoint.connectedBody=other.rigidbody;

                myjoint.breakForce=force;
                myjoint.breakTorque=torque;
                print("breakForce=\n" + gameObject.GetComponent<CharacterJoint>().breakForce);
                print("breakTorque=\n" + gameObject.GetComponent<CharacterJoint>().breakTorque);
            }
        }
    }
}

c# unity3d

2022-09-30 19:40

2 Answers

breakForce is "force required to disconnect" and breakTorque is "torque required to disconnect" which causes a characterJoint to spin more than a point of time.Due to the high speed of the projectile, may the projectile still be accelerating at the time of impact?

You might want to try setting Mathf.Infinity for both breakForce and breakTorque.

If the bullet sticks together, you can balance it with the speed of the bullet to make it work as you want, or increase the breakForce and breakTorque above the collision point value.


2022-09-30 19:40

First of all, the CharacterJoint is connected, right?
This joint is like a spring, so maybe it landed in an extended state and stopped.

How about FixedJoint?


2022-09-30 19:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.