Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

How to include collider to a gameobject?

Discussion in 'Getting Started' started by NyanGoodWill, Sep 13, 2017.

  1. NyanGoodWill

    NyanGoodWill

    Joined:
    Sep 6, 2017
    Posts:
    8
    I am trying to hit a ball using a golf club. My golf club has three components (three game objects: handle, shaft and head as shown in the attached file gameobjects.png). Head gameobject's inspector can be seen in the another attached image.
    To hit the golf ball, we need a collider. So I put a Capsule Collider at head game object. But I don't see any collider at head gameobject.
    The head is shown in the scene image in the attached file.
    Why I can't put Capsule Collider at the object?
     

    Attached Files:

  2. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    600
    Hi @NyanGoodWill welcome to the forum! :)

    To hit the golf ball, you need two colliders. One on the head (of the golf club brat) and one on the ball.

    Probably is better to put a box collider with the same rotation of the head surface, if you what to use Physics to make the simulation.

    "The head is shown in the scene image" is showing the yellow collider capsule is properly attached to the game object head correctly.

    In any way, you also need a Rigidboady.

    You need one RB (Rigidboady) for the gold club and other RB for the ball. When moving a game object, it’s imperative to add a RigidBody to it.

    When you are moving colliders too fast or the colliders are to small there are cases when they do not collide. This happens because there is not instant that are colliding. Sory for my English. In one physic instant the head was going to make the collision with the ball and in the next physic instant the head passes the ball and no Collider was occluded, no collision occurred. There was not an instant that objects were colliding. To resolve this, you need to increase the physic time resolution and or make the header collider bigger.

    "Fixed Timestep
    Tweak the Fixed Timestep value on the Time Manager, this directly impacts the FixedUpdate() and Physics update rate. By changing this value you can try to reach a good compromise between accuracy and CPU time spent on Physics."Ricardo Aguiar

    You must take into account also that the header collider can touch the ground. And you must prevent this also.

    another way is just to give impulse force to the Rigidbody ball without the actual simulation of the hit.

    I suggest you, take a look and follow this project tutorial: https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial
    And also Look for the physics video tutorial.
     
    Last edited: Sep 13, 2017
    NyanGoodWill likes this.
  3. NyanGoodWill

    NyanGoodWill

    Joined:
    Sep 6, 2017
    Posts:
    8
    Thanks @AlanMattano for good explanation.Let me explore more. I am new to Unity so your advise are useful.