hi, so I have this game Im making on unity3d. As you can see the claw is going to pull the bowl, to which ever direction the user moves the robot arm. My claw hand is made of animation. Everything works except the shooting the ball. Im using a spring joint on the bowl so it goes back to its place but when i try to grab the bowl, it grabs a specific part of the bowl and it makes the ball come out when i move the ball up, down , left or right. Even though when i play the game and dont move it , the ball stays in the bowl. Maybe because I pull it to fast so the ball falls through the bowl. i dont know how to fix that. if thats the case. This is my code: `
public float speed;
private Animation anim;
[SerializeField] bool isClosed;
Rigidbody rb;
public Transform rightClaw;
public Vector3 offset;
Collider objectholder;
void Start()
{
Debug.Log(transform.position);
Console.WriteLine("test");
anim = gameObject.GetComponent<Animation>();
rb = GetComponent<Rigidbody>();
}
void Update()
{
// Debug.Log(transform.position);
if (Input.GetKey(KeyCode.X))
{
anim.Play("clawopen");
isClosed = false;
}
if (Input.GetKey(KeyCode.Y))
{
anim.Play("clawclose");
isClosed = true;
}
}
private void OnTriggerStay(Collider objectholder)
{
Rigidbody colRb = objectholder.attachedRigidbody;
if (isClosed && objectholder.transform.gameObject.tag == "Player")
{
objectholder.transform.position = rightClaw.transform.position offset;
}
}
private void OnTriggerEnter(Collider objectholder)
{
Rigidbody colRb = objectholder.attachedRigidbody;
if (isClosed && objectholder.transform.gameObject.tag == "Player")
{
colRb.Sleep();
}
}
private void OnTriggerExit(Collider objectholder)
{
Rigidbody colRb = objectholder.attachedRigidbody;
if (isClosed && objectholder.transform.gameObject.tag == "Player")
{
colRb.WakeUp();
}
}
} ` How can I make the ball stay in the bowl until it gets let go so it can get thrown . or can I code the ball and this bowl without a spring joint so it can go back to its original place and the ball can shoot. please and thank you
CodePudding user response:
This is my no-script setup:
I would just make the Ball & Bucket kinematic
until you release it. No matter if It's controlled by animation or scrip/mouse/touch.
I used 2 Spring joints to keep the bucket on an almost straight line between the 2 gray dots. So it accelerates forwards but doesn't spin around.
A few notes on this kind of setup: MeshColliders need to be marked "convex" for physics to work. But a bucket collider will be "filled" by checking "convex" so you have to make it submeshes or use a few cube colliders to imitate the buckets shape.
Both, ball and bucket need to have a Rigidbody.