Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Bow and Arrow Collider Problem

Discussion in 'Physics' started by hellboy1998, Jun 23, 2021.

  1. hellboy1998

    hellboy1998

    Joined:
    Nov 5, 2018
    Posts:
    3
    Hello everyone... wish you have a nice day without bugs;););) i have an issue about the colliders:
    I am creating an archer simulator in unity and i created bow and arrow mechanism. Everything seems good until this arrow stick where there is no collider(In gif at the bottom of target)
    Animation.gif
    My target collider seems like that:
    upload_2021-6-23_13-13-54.png

    One confusing part is that when i turned target into trigger everything works fine...but when i use non-trigger collider, it touch the "invisible collider"...
    The code i used for arrow:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ArrowController : MonoBehaviour
    6. {
    7.     Rigidbody arrowRb;
    8.  
    9.     public float despawnTime;
    10.  
    11.     private bool isCollided = false;
    12.  
    13.     private bool isLaunched = false;
    14.  
    15.     private void Start()
    16.     {
    17.         arrowRb = GetComponent<Rigidbody>();
    18.         arrowRb.isKinematic = true;
    19.     }
    20.  
    21.     private void FixedUpdate()
    22.     {
    23.         if (isCollided)
    24.         {
    25.             return;
    26.         }
    27.         if (isLaunched)
    28.         {
    29.             arrowRb.transform.rotation = Quaternion.LookRotation(arrowRb.velocity);
    30.         }
    31.        
    32.     }
    33.  
    34.     public void LaunchArrow(float shootForce)
    35.     {
    36.         isLaunched = true;
    37.         transform.parent = null;
    38.         arrowRb.isKinematic = false;
    39.         arrowRb.velocity = arrowRb.transform.forward * shootForce;
    40.     }
    41.  
    42.     //private void OnTriggerEnter(Collider other)
    43.     //{
    44.     //    isCollided = true;
    45.     //    StickPlace();
    46.     //}
    47.  
    48.     private void OnCollisionEnter(Collision collision)
    49.     {
    50.         isCollided = true;
    51.         StickPlace();
    52.     }
    53.     private void StickPlace()
    54.     {
    55.         arrowRb.constraints = RigidbodyConstraints.FreezeAll;
    56.     }
    57. }
    58.  
     
  2. JRRReynolds

    JRRReynolds

    Joined:
    Oct 29, 2014
    Posts:
    192
    Throw a debug log in OnCollisionEnter to see what gameobject you are colliding with first
     
    MadeFromPolygons likes this.
  3. hellboy1998

    hellboy1998

    Joined:
    Nov 5, 2018
    Posts:
    3
    I tried it but debug menu shows cube with collider(not trigger)
     
  4. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Check the size and orientation of the arrow colliders mesh, I suspect it could be different to the arrow. e.g. up/down instead of horizontal.

    This often happens when you have to rotate a mesh to point forward then add the collision mesh with the original rotation.
     
  5. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,759
    Why are the drawstring and arrows during the third and later shots turning red in the hierarchy when you use/spawn them?
     
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,325
    Try doing this:

    1. Shoot several arrows.
    2. Pause the game
    3. Switch to the scene view (not game view)
    4. Select all objeects in the scene.

    This should display all colliders, so you might be able to figure out what is interfering.