Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by yzh02 · Jul 16, 2021 at 04:32 AM · default

OnCollisionStay not working when game is built

Hi, I was wondering why my collisions aren't working properly, specifically on Void OncollisionStay. I've also tried to use OnCollisionEnter getting no result when I build the game as counterpart when I test the game in the editor everything works really well. to give some context, this script is for a bullet which it will chase to the enemy "obj" unit Oncollisionstay detect him and then, calling the function "vida_ enemigo()" to substract some health "enem.vida". I would be so grateful if anyone could help me pls. :( here's my code:

    public int damage;//modificar en inspector
     public GameObject obj;//no modificar
     public float velocidad;//modificar en inspector
     Rigidbody rgb;//no modificar
     public bool inicializar = false;//no modificar
     
     void Start()
     {
         rgb = gameObject.GetComponent<Rigidbody>();
     }
 
     // Update is called once per frame
     void Update()
     {
 
         if (obj && inicializar)
         {
             transform.eulerAngles = new Vector3(0, angulo_a_rotar(obj) - 180, 0);
             rgb.transform.Translate(Vector3.forward * Time.deltaTime * velocidad);
         }
         if( !obj && inicializar)
         {
             Destroy(gameObject);
         }
         /*if(obj && checkear_distancia(0.3f, obj))
         {
             vida_enemigo(obj);
         }*/
         
     }
 
     private void OnCollisionStay(Collision collision)
     {
         if (obj == collision.gameObject)
         {
             vida_enemigo(collision.gameObject);
         }
     }
     void vida_enemigo(GameObject enemigo)
     {
         vida_enemigo enem = enemigo.GetComponent<vida_enemigo>();
         enem.vida -= damage;
         DestroyImmediate(gameObject);
 
     }
     float angulo_a_rotar(GameObject obj)
     {
         float dist = 0;
         float eje_x = obj.transform.position.x - transform.position.x;
         float eje_z = obj.transform.position.z - transform.position.z;
         dist = Mathf.Sqrt(eje_x * eje_x + eje_z * eje_z);// dist de esta torreta hasta el enemigo
 
         float dist_2 = 0;
         float eje_x_2 = obj.transform.position.x - transform.position.x;
         float eje_z_2 = obj.transform.position.z - transform.position.z + dist;
         dist_2 = Mathf.Sqrt(eje_x_2 * eje_x_2 + eje_z_2 * eje_z_2);// dist del (torretax, torretaz + dist) hasta el enemigo
 
         float dist_3 = dist;// dist de la torreta hasta (torretax, torretaz + dist) 
 
         float angulo = (180 / Mathf.PI) * Mathf.Acos(-1 * (dist_2 * dist_2) / (2 * dist_3 * dist) + (dist_3) / (2 * dist) + (dist) / (2 * dist_3));
         if (obj.transform.position.x > transform.position.x)
         {
             angulo *= -1;
         }
 
         return angulo;
     }
 
     bool checkear_distancia(float distancia, GameObject obj)
     {
         float dist = 0;
         float eje_x = obj.transform.position.x - transform.position.x;
         float eje_z = obj.transform.position.z - transform.position.z;
         dist = Mathf.Sqrt(eje_x * eje_x + eje_z * eje_z);
         if (dist <= distancia)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
 }




Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yzh02 · Jul 15, 2021 at 01:57 AM 0
Share

I figured out!, it was an issue that i committed with some tags of an GameObject. Nothing related to this issue :').

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

251 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't see GameObjects In Scene View 2 Answers

when i try to build for window platform 82 and 64 both ;( 0 Answers

[SOLVED] Constructors with unexpected default values 1 Answer

Changing material dose not change the appearance of the game object 0 Answers

Unity IAP not working for android need google public key 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges