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 /
avatar image
0
Question by tayyab43 · May 26, 2014 at 03:31 PM · bullet

when the bullet hits the bot it still makes the bullet hole

Basically my script for bullet holes doesn't seem to be working correctly it makes a bullet hole as usual but it still makes a bullet hole when it hits my bot, why? Here's my code for the bullet hole:

 var life : float = 0.5;
 var bulletSpeed : float = 1.0;
 var dustPrefab : GameObject;
 var bulletHolePrefab : GameObject;
 
 private var destroyTime : float;
 private var velocity : Vector3;
 private var gravity : float = 9.8;
 public var Soldier : GameObject ;
 var makeHole : boolean;
 function Start(){
     destroyTime = Time.time + life;
     velocity += transform.forward * bulletSpeed;
     Soldier=GameObject.FindWithTag("BOT");
 }
 
 
 
 
 function OnTriggerEnter(other:Collider)
 {
    if(other.gameObject.tag=="BOT")
     makeHole=false;   
 }
 
 
 function Update () {
     
     if(Time.time > destroyTime){
         Destroy(gameObject);
     }
     var ray : Ray;
     ray.origin = transform.position;
     ray.direction = transform.forward;
     var hit : RaycastHit;
     if (Physics.Raycast(ray,hit,bulletSpeed*Time.deltaTime)){
         triggerChildrenColliderScript = hit.transform.root.GetComponent(triggerChildrenCollider);
         var reCheck : boolean; //Re-check if there's a hit for children collider.
         var mainColliderHit : Collider = hit.collider; //Parent collider. (must be re enabled)
         if(triggerChildrenColliderScript != null){ //Trigger children property. Enable children collider and disable root collider.
             hit.collider.enabled = false;
             var childrenColliderList : Collider[] = triggerChildrenColliderScript.childrenColliderList;
             for (var i = 0; i < childrenColliderList.Length; i++){
                 childrenColliderList[i].enabled = true;
             }
             reCheck = Physics.Raycast(ray,hit,bulletSpeed*Time.deltaTime); //Recheck collision for children collider.
         }
         if(reCheck || triggerChildrenColliderScript == null){ //If children collider or root collider are hit, process the bullet hit.
             Destroy(gameObject);
             var makeDust : boolean = true;
             //var makeHole : boolean = true;
             var bulletHolePropertyScript : bulletHoleProperty =  hit.transform.root.GetComponent(bulletHoleProperty);
             var extraPrefab : GameObject;
             var holeSize : float = 1.0;
             var differentBulletMaterialArray : Material[];
             if (bulletHolePropertyScript != null){ //Bullet hole property.
                 makeDust = bulletHolePropertyScript.dust;
                 makeHole = bulletHolePropertyScript.hole;
                 extraPrefab = bulletHolePropertyScript.extraPrefab;
                 holeSize = bulletHolePropertyScript.sizeModifier;
                 bulletMaterials = bulletHolePropertyScript.bulletMaterials;
             }
             if (extraPrefab != null){ //Extra prefab.
                 Instantiate(extraPrefab,transform.position,transform.rotation);
             }
             if (makeDust){ //Dust.
                 var newdustCloudGenerator : GameObject = Instantiate(dustPrefab,hit.point - transform.forward*0.1, Quaternion.identity);
                 newdustCloudGenerator.GetComponent(dustCloudGenerator).velocity = hit.normal * (2 + Random.value*10);
             }
             if (makeHole){ //Bullet hole.
                 var newBulletHole : GameObject = Instantiate(bulletHolePrefab, hit.point + hit.normal *0.01, Quaternion.identity);
                 newBulletHole.transform.LookAt(newBulletHole.transform.position + hit.normal);
                 newBulletHole.transform.parent = hit.collider.transform;
                 var bulletHoleScript : bulletHole = newBulletHole.GetComponent(bulletHole);
                 bulletHoleScript.size *= holeSize;
                 if (bulletHolePropertyScript != null && bulletMaterials.Length > 0){
                     bulletHoleScript.materials = bulletMaterials;
                 }    
             }
             if(hit.rigidbody != null){ //Apply force.
                 hit.rigidbody.AddForceAtPosition(velocity* 1.5, hit.point);
             }
             var healthScript : health = hit.transform.root.GetComponent(health); //Health property.
             if(healthScript != null){
                 healthScript.health -= 20;
                 healthScript.SetLastHitTime();
                 var hitPointNoHeight : Vector3 = hit.point;//hit.point;
                 hitPointNoHeight.y = hit.transform.position.y;
                 var hitDirection : Vector3 = hitPointNoHeight - hit.transform.position;
                 hitDirection.Normalize();
                 hitDirection = hit.transform.root.InverseTransformDirection(hitDirection);
                 healthScript.SetHitDirection(hitDirection);
                 var recoilDirection : Vector3 = hit.transform.position - hitPointNoHeight;
                 recoilDirection.Normalize();
                 healthScript.SetrecoilDirecion(recoilDirection);
             }
         }
         if(triggerChildrenColliderScript != null){//Trigger children property. Disable children collider and enable root collider.
             mainColliderHit.enabled = true;
             for (var n = 0; n < childrenColliderList.Length; n++){
                 childrenColliderList[n].enabled = false;
             }
         }
     }
 
     velocity.y -= gravity * Time.deltaTime;
     transform.position += velocity * Time.deltaTime;
     transform.LookAt(transform.position + velocity);
 }

 
Comment
Add comment · Show 8
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 tayyab43 · May 27, 2014 at 11:39 AM 0
Share

anyone?, i don't get why it isn't working?

avatar image tayyab43 · May 27, 2014 at 12:44 PM 0
Share

anyone?????

avatar image CrimsonIndustry · May 28, 2014 at 06:42 PM 0
Share

Your question is very unclear - what is your desired behavior? Bullets make holes when they hit objects - do you not want that?

avatar image tayyab43 · May 29, 2014 at 01:51 PM 0
Share

sorry, i don't want it to make a bullet hole when it hits a BOT that is tagged "BOT"

avatar image tayyab43 · May 30, 2014 at 02:23 PM 0
Share

$$anonymous$$an this problem is annoying me

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Griffo · May 30, 2014 at 03:39 PM

Do you just see a few bullet hole then they stop or bullet holes all the time your shooting ?

Try this .. delete lines 70 to 79 then replace with ..

 if(makeHole){
     bulletHole():
 }

Then add this function at the bottom of your script ..

 function bulletHole(){
 
     yield WaitForSeconds(0);
     var newBulletHole : GameObject = Instantiate(bulletHolePrefab, hit.point + hit.normal *0.01, Quaternion.identity);
     newBulletHole.transform.LookAt(newBulletHole.transform.position + hit.normal);
     newBulletHole.transform.parent = hit.collider.transform;
     var bulletHoleScript : bulletHole = newBulletHole.GetComponent(bulletHole);
     bulletHoleScript.size *= holeSize;
     if (bulletHolePropertyScript != null && bulletMaterials.Length > 0){
         bulletHoleScript.materials = bulletMaterials;
     }
 }

Just want to try a pause for 1 frame to give OnTriggerEnter time to work.

Have you tried to debug OnTriggerEnter ? ..

Replace function OnTriggerEnter with ..

 function OnTriggerEnter(other:Collider){
 
     if(other.gameObject.tag=="BOT")
         makeHole=false;
         print("BOT entered trigger ..");
     }
 }

And see if "BOT entered trigger .." is printed to the console when a BOT enters the trigger.

Is the BOT's Is Trigger ticked on their colliders in the inspector ?

Comment
Add comment · Share
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

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

23 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

Related Questions

Bullet Collision disables/re-enable mesh renderer & collider 1 Answer

HipFire???? 0 Answers

Prevent Bullets from going through objects/ No raycast 3 Answers

Bullets sometimes shoot under map 1 Answer

Random Raycast inside crosshairs 1 Answer


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