Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 TheChanger · Apr 20, 2019 at 12:32 PM · instantiatebullethole

Bullets holesnot instantiating in the correct position

I have been following a tutorial series by a youtube channel called Jimmy Vegas and after watching his video on bullet holes and how to make them appear where you fire I found that the bullet holes either instantiate inside the wall or are floating in mid-air. Any help would be great. Here is the code I have used: using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PistolDamage : MonoBehaviour { public int pistolDamage = 5; public float TargetDistance; public float rangePistol = 15.0f; public GameObject gunObject; public GameObject zombie; public GameObject bullet; public RaycastHit hit; // Start is called before the first frame update void Start() {

 }

 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Z))
     {
         
         if (GunScript.reloading == false)
             {
             
             RaycastHit Shot;       
             if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out Shot))
             {
                 TargetDistance = Shot.distance; 
                 if (TargetDistance < rangePistol)
                 {                                                                         
                     Shot.transform.SendMessage("DeductPoints", pistolDamage, SendMessageOptions.DontRequireReceiver);
                     if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit))
                     {
                         Instantiate(bullet,hit.point,Quaternion.LookRotation(hit.normal));
                     }  
                 }



                 }
             }
         
         
     }
     
 }

}

Comment
Add comment · Show 2
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 akaBase · Apr 20, 2019 at 12:47 PM 0
Share

Why are you using a second raycast?, you could just use the first ones Shot.normal? Also, to save on overhead you could just set the max range for the raycast to be that of the weapon being used and then its a case of if it hits or not, no check of the distance would be needed.

But to answer your question, put it in a FixedUpdate for collision detection.

Update runs once per frame. FixedUpdate can run once, zero, or several times per frame, depending on how many physics frames per second are set in the time settings, and how fast/slow the framerate is.

avatar image TheChanger akaBase · Apr 20, 2019 at 09:16 PM 0
Share

Thanks for the help. Sorry I still have a lot to learn with C#. Hopefully I can learn from them!

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

127 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

Related Questions

Checking if object intersects? 1 Answer

assign different values to prefabs on instantiation 2 Answers

How to associate underlying data structure to prefab at runtime? 1 Answer

setting the text of an instantiated prefab's child's guitext object 1 Answer

Prefab instead of class oClass = new class() ? 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