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 MadJohny · Jul 24, 2013 at 03:08 PM · raycastscalebullethitraycastall

EteeskiTutorials' bullets (raycast bullets with gravity)

Hi, for my game I used EteeskiTutorial's bullets from one of his series ( http://www.youtube.com/watch?v=kx7PcUzhG_8&list=PLfAMZpOjTmpbr9EN9FwK76Hdr_bWMDxdH ), I only used the tutorial [1/5] though because it's the only one that I need for my game, the problem is that the bullets in my game compared to his are huge, but with this I mean like, they are slow, and have almost same widht as a player/enemy, so how can I make multiple raycasts so it hits with the true size of the object? since you probably won't watch a tutorial just to help me, here, have my script (and it's actually in c#, he did it in js)

 public class Projectile : MonoBehaviour {
 
     public float speed = 100f;
     public float lifeTime = 7f;
     public GameObject decalHitWall;
     
     [HideInInspector]
     public Vector3 moveDirection;
     [HideInInspector]
     public float shortestSoFar;
     
     [HideInInspector]
     public Vector3 instantiatePoint;
     [HideInInspector]
     public Quaternion instantiateRotation;
     [HideInInspector]
     public bool foundHit = false;
     
     public bool damagePlayer = false;
     public int damage = 20;
     
     void Awake () {
         moveDirection = transform.forward * speed;
         shortestSoFar = Mathf.Infinity;
         foundHit = false;
         
     }
     
     void Update () {
         transform.rotation = Quaternion.LookRotation(moveDirection);
         RaycastHit[] hits;
         hits = Physics.RaycastAll(transform.position, transform.forward, speed * Time.deltaTime);
         foreach (var hit in hits){
             float tempDistance = Vector3.Distance(transform.position, hit.point);
             if(tempDistance < shortestSoFar){
                 instantiatePoint = hit.point;
                 instantiateRotation = Quaternion.LookRotation (hit.normal);
                 shortestSoFar = Vector3.Distance(transform.position, hit.point);
                 foundHit = true;
                 GameObject spawnParticles = (GameObject)Instantiate (decalHitWall, instantiatePoint, instantiateRotation);
                 if(hit.transform.tag == "Enemy" && !damagePlayer){
                     hit.transform.parent.GetComponent<EnemyScript>().health -= damage;
                     shortestSoFar = Vector3.Distance(transform.position,hit.point);
                     Destroy (transform.root.gameObject);
                 }
                 if(hit.transform.tag == "Player" && damagePlayer){
                     hit.transform.GetComponent<Player>().health -= damage;
                     shortestSoFar = Vector3.Distance(transform.position,hit.point);
                     Destroy (transform.root.gameObject);
                 }
                 if(hit.transform.tag == "LevelPart"){
                     Destroy (transform.root.gameObject);
                     shortestSoFar = Vector3.Distance(transform.position,hit.point);
                 }
             }
         }
         
         transform.position += moveDirection * Time.deltaTime;
         
         lifeTime -= Time.deltaTime;
         
         if(lifeTime <= 0f){
             Destroy(gameObject);
         }
     }
 }

Thanks in advace

Comment
Add comment · Show 4
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 MadJohny · Jul 24, 2013 at 05:39 PM 0
Share

yeah but... could you write a script? I don't know how I could put 3 raycast's information in only one....

avatar image amphoterik · Jul 24, 2013 at 06:30 PM 0
Share

You are already raycasting once in your scene. Just do it 2 more times.

avatar image MadJohny · Jul 24, 2013 at 07:50 PM 0
Share

Thanks, it worked, convert into an answer so I can accept it please, and the bullets sometimes go trought enemies, but this happens since the first time I tried them, it's really weird I must talk to eteeski himself

avatar image amphoterik · Jul 24, 2013 at 08:59 PM 0
Share

Ok, I did. Glad it helped.

1 Reply

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

Answer by amphoterik · Jul 24, 2013 at 03:18 PM

Just cast multiple rays from the bullet. One in each "corner" and the middle should do.

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

16 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

Related Questions

Penetration weapon needs to find all objects it passes through 1 Answer

instantiate decal at raycastHit 1 Answer

2D Raycast doesn't Hit colliders 1 Answer

[CLOSED]RaycastAll Help 1 Answer

Ray curve for bullet gravity effect, or any way to make it 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