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
-1
Question by Vincent-Terra · Nov 10, 2012 at 12:33 AM · c#raycastingbullets

Problem with Raycast

Well basically I have a cube which when within a certain range from my first person control, starts shooting bullets. There is a problem with the raycasting used to detect when the bullets hit the player. For some reason the bullets get deleted immediately after instantiation though and I can't figure why. This is the script of the bullet prefab used to destroy the bullets and change the HP of the player if the bullets hit him.

 using UnityEngine;
 using System.Collections;
 
 public class deletion : MonoBehaviour {
     
     public int death_counter;
     public int damage;
     
     // Use this for initialization
     void Start () {
     Destroy(gameObject, death_counter);
     }
     
     void Update () {
         
      Vector3 fwd = transform.TransformDirection(Vector3.forward);
      RaycastHit hit;
 
         if (Physics.Raycast(transform.position, fwd, out hit, 0.051f) )
             if (hit.collider.name == "Player") {
             HP health = GameObject.Find("Player").GetComponent<HP>();
             health.curHp = health.curHp - damage;
         }
             Destroy(gameObject);
         
     }
 }

Any help would be appreciated!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Benproductions1 · Nov 10, 2012 at 07:24 AM

If you would desk-check your program you would know why your bullets only appear for one frame.

In the first frame after instantiation, they calculate if they hit the player, then they destroy themselves. You will have to make some major adjustments to your bullet logic to make it do what I think you want it to do.

Raycasts are quite instant, they don't take multiple frames to compute.

Your welcome, Benproductions1

Comment
Add comment · Show 1 · 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
avatar image Vincent-Terra · Nov 10, 2012 at 09:58 AM 0
Share

Thanks for your answer! I will adjust the if conditions! Program$$anonymous$$g at 3 am is not productive.

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

problems with particlesystem effect as a bullet tracer 0 Answers

Rotation along edge of a cube around another cube as its planet 1 Answer

Bullet moving backwards with Hermite Spline Controller 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