Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 andredewaard · Sep 16, 2014 at 08:37 PM · variablefunctionshotbullethole

bullet hole on shot

I have this script that shoots a bullet from my muzzlePoint to my cursor. If i want to add a bullet hole the bullet hole will be on the wall before the bullet hits. So i wanted to use the function OnTriggerEnter. How can i get this to work when it shoots?

 #pragma strict
 var bullet : Transform; // the bullet prefab
 private var spawnPt : GameObject; // holds the spawn point object
 var bulletHole : Transform;
  
 function Start()
 {
  
 }
  
 function Update()
 {
      if(Input.GetMouseButtonDown(0))
      { 
  
        // only do anything when the button is pressed:
 
         var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         var hit : RaycastHit;
 
         if (Physics.Raycast (ray, hit, 100))
         {
             if (!spawnPt) spawnPt = GameObject.Find("muzzlePoint");
             var projectile = Instantiate(bullet, transform.position,   Quaternion.identity);         
             
             projectile.transform.rotation = Quaternion.LookRotation(ray.direction);
             projectile.rigidbody.AddForce(ray.direction * 1000);
         }
 
         OnTriggerEnter();
 
         audio.Play();
      }
 }
 
         function OnTriggerEnter (other : Collider) {
             var hit : RaycastHit;
             if (other.gameObject.tag == "wall") {
                 var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
                 Instantiate(bulletHole, hit.point, hitRotation);
             }
         }
 


Comment
Add comment · Show 3
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 Graham-Dunnett ♦♦ · Sep 16, 2014 at 08:39 PM 0
Share

The usual way to do this is to fire a ray from the bullet each frame with a ray length related to how far the bullet with travel in the next frame, effectively it's velocity multiplied by deltaTime. If the ray passes through the wall, then you know the bullet is about to hit.

avatar image Bluntweapon · Sep 16, 2014 at 08:44 PM 0
Share

Not entirely sure what you're getting at, since there was a lot of ambiguous use of the English language there. $$anonymous$$y guess is you want a Bullet Hole to spawn when the bullet hits a wall, is this correct?

avatar image andredewaard · Sep 18, 2014 at 11:02 AM 0
Share

Yes this is correct. Excuse me for my English it is not my native language.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

iTween - calling functions on oncomplete doesn't work if the function is declared as a variable 1 Answer

How to correctly send a variable to another function? 1 Answer

Calling non applied scripts 3 Answers

Cleaning up my item script... Passing script name to function? 0 Answers

Glitchy variable when updating through a function 2 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