Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by hballamco · Feb 09, 2020 at 07:15 AM · gameobjecttimelinerenderergizmosradius

two objects with same volume of effect; One affect but other do not

Hello, so I made two objects. Both have the same radius of effect. Yet when I start playing, one of them works completely fine but the other affect too small volume of effect even when they have same volume of effect. This is the code for the one with problem:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LaserBeam : MonoBehaviour
 {
     public float damageOverTime = 3f;
     public float radiusOfEffect = 30f;
     public float laserOrbTime = 10f;
 
     LineRenderer laser;
 
     // Find closest gameobject with tag "Enemy"
     public GameObject FindClosestEnemy()
     {
         GameObject[] enemies;
         enemies = GameObject.FindGameObjectsWithTag("Enemy");
         GameObject closest = null;
         float distance = radiusOfEffect;
         Vector3 position = transform.position;
 
         foreach (GameObject enemy in enemies)
         {
             Vector3 diff = enemy.transform.position - position;
             float curDistance = diff.sqrMagnitude;
 
             if (curDistance < distance)
             {
                 closest = enemy;
                 distance = curDistance;
             }
         }
         return closest;
     }
 
     // Start is called before the first frame update
     void Start()
     {
         // Remove laser orb
         Destroy(gameObject, laserOrbTime);
         laser = GetComponent<LineRenderer>();
     }
 
     // Update is called once per frame
     void Update()
     {
         if (FindClosestEnemy() != null)
         {
             laser.enabled = true;
             laser.SetPosition(0, transform.position);
             laser.SetPosition(1, FindClosestEnemy().transform.position);
 
             // Damage
             Target target = FindClosestEnemy().GetComponent<Target>();
             if (target != null)
             {
                 target.LaserDamage(damageOverTime);
             }
         }
 
         else
         {
             laser.enabled = false;
         }
     }
 
     private void OnDrawGizmosSelected()
     {
         Gizmos.color = Color.red;
         Gizmos.DrawWireSphere(transform.position, radiusOfEffect);
     }
 }

Now this is the code of the fine one:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BlackHole : MonoBehaviour
 {
     public float radiusOfEffect = 30f;
     public float BlackHoleforce = 0.5f;
     public float forceIncrementOverTime = 1f;
     public float damageOverTime = 3f;
     public float blackHoleTime = 7f;
 
     // Start is called before the first frame update
     void Start()
     {
         // Remove black hole
         Destroy(gameObject, blackHoleTime);       
     }
 
     // Update is called once per frame
     void Update()
     {
         Collider[] colliders = Physics.OverlapSphere(transform.position, radiusOfEffect);
 
         foreach (Collider nearbyObject in colliders)
         {
             Target target = nearbyObject.GetComponent<Target>();
             Rigidbody rb = nearbyObject.GetComponent<Rigidbody>();
 
             // Add force
             if (rb != null)
             {
                 rb.AddExplosionForce(-BlackHoleforce, transform.position, radiusOfEffect);
                 BlackHoleforce += forceIncrementOverTime * Time.deltaTime;               
             }
             
             // Damage            
             if (target != null)
             {
                 target.BlackHoleDamage(damageOverTime);
             }
         }
     }
 
     private void OnDrawGizmosSelected()
     {
         Gizmos.color = Color.red;
         Gizmos.DrawWireSphere(transform.position, radiusOfEffect);
     }
 }

Here is the picture of both objects with their gizmos drawn: alt text

As you can see in the codes, I included a float which is radius of effect and they both the same yet in reality one affects all inside radius. Other affects really small radius even when it's gizmo shows otherwise. Please help.

capture.jpg (180.3 kB)
Comment
Add comment
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

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

186 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

Related Questions

speed change in standalone compared to editor? 1 Answer

Linerenderer between RaycastHit.point and a Gameobject 1 Answer

Instantiate clones with error. 1 Answer

Reset speed after a specified time 1 Answer

How to draw line between array's gameobjects 3 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