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 seashell · Jul 10, 2012 at 01:46 PM · bulletgunhit

Detection bullets hit

Is there any way to get from EmptyGameObject, what he hitted and where? Not loosing FPS, for example for scene, where going to be, more than 1000+ bullets (for IOS).

Gun Script (that shoots empty game objects with sprite on them):

 #pragma strict
 
 var bulletPrefab : GameObject;
 var spawnPoint : Transform;
 var frequency : float = 10;
 var coneAngle : float = 1.5;
 var firing : boolean = false;
 var damagePerSecond : float = 20.0;
 var forcePerSecond : float = 20.0;
 var hitSoundVolume : float = 0.5;
 
 private var lastFireTime : float = -1;
 function fireOn()
 {
 var coneRandomRotation = Quaternion.Euler (Random.Range (-coneAngle, coneAngle), Random.Range (-coneAngle, coneAngle), 0);
 if (Time.time > lastFireTime + 1 / frequency)
 {
 lastFireTime = Time.time;
 var bulletfly = Instantiate(bulletPrefab, spawnPoint.transform.position, spawnPoint.transform.rotation*coneRandomRotation);
 }
 }
 
 function Start () {
 
 }
 
 function Update () {
 fireOn();
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Mr.Jwolf · Jul 10, 2012 at 02:49 PM

You can use Raycasting. Your bulletPrefab should have a script that tests if it hits something (this requires the objects you want to hit, to have a collider).

The bullet script could look like this:

#pragma strict

// The position in the previous frame private var previousPosition: Vector3;

function Start () { previousPosition = transform.position; }

function Update () { Fly(); HitTest(); }

function Fly() { //... moves the bullet ... }

function HitTest() { var forwardDirection = transform.forward; var raycastDistance : float = Vector3.Distance(transform.position, previousPosition); var raycastHitInfo : RaycastHit; // Makes a raycast that returns true if it hits any colliders. if (Physics.Raycast (previousPosition, forwardDirection, raycastHitInfo, raycastDistance)) { // -- Hitted a collider -- OnBulletHit(raycastHitInfo); } previousPosition = transform.position; }

function OnBulletHit(raycastHitInfo : RaycastHit) { var hitObject : GameObject = raycastHitInfo.transform.gameObject; Debug.Log("Hitted: "+hitObject +" at point: "+raycastHitInfo.point); // ((AIScript) hitObject.GetComponent("AIScript")).OnBulletHit(); Destroy (gameObject); }

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 seashell · Jul 11, 2012 at 10:54 AM 0
Share

thanks man! Perfect!

avatar image
0

Answer by Ranger-Ori · Jul 10, 2012 at 02:08 PM

Yes, if you are using raycasting, you can save the points (Vector3). Which afterward you can use for anything you would like. I wouldn't save all of the points, for as you said, it will decrease the FPS and performance, however, you can use just one variable for a point and use it to "capture" each of the shots.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Prevent Bullets from going through objects/ No raycast 3 Answers

Ammo Script 1 Answer

Rotate Bullet with rotating Turret PROPERLY 2 Answers

Circular Bullet Spread for Shotgun / Bloom 1 Answer

Beginner to raycasting: making a gun 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