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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by greg1992 · Mar 22, 2013 at 12:47 AM · c#collisionprojectiles

Error CS1501, Projectiles spawning.

My bullet projectiles are being fired from the turret, and ending up spawning ontop of another, furthermore they don't move. I've tried adding Physics.IgnoreCollision(bullet.collider);

However that generates the error; error CS1501: No overload for method IgnoreCollision' takes1' arguments

 void Update(){
 
  TargetEnemy(); // update the selected target and look at it
 
 if (selectedTarget){ // if there's any target in the range...
 
 transform.LookAt(selectedTarget); // aim at it
 
 if (Time.time >= shootTime){ // if it's time to shoot...
 
 Rigidbody bullet = (Rigidbody)Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
 
 
 }    
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
Best Answer

Answer by Chronos-L · Mar 22, 2013 at 01:45 AM

Physics.IgnoreCollision() takes 2 or 3 arguments.

  • Physics.IgnoreCollision( colliderA, colliderB ) : colliderA and colliderB will not collide

  • Physics.IgnoreCollision( colliderA, colliderB, false ) : colliderA and colliderB will collide

Physics.IgnoreCollision(bullet.collider) is incorrect, you need to define what collider the bullet will ignore.

Comment
Add comment · Show 7 · 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 greg1992 · Mar 22, 2013 at 01:53 AM 0
Share

I see, so something like this?

Physics.IgnoreCollision( bullet.collider, collider );

that doesn't give me the error anymore, but the bullets are moving just spawning ontop of one another. I take it that the above code is wrong.

avatar image Chronos-L · Mar 22, 2013 at 01:56 AM 0
Share

You need to apply force to your bullet, after you instantiate it.

Rigidbody.AddForce()

avatar image greg1992 · Mar 22, 2013 at 02:02 AM 0
Share

hmmm i am, i'm down with a first person camera, and i can see the bullets following the position of the targets, but they're not moving at all. Used Rigidbody.AddForce() ins$$anonymous$$d of bullet.AddForce but to no avail.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class TurretScript : $$anonymous$$onoBehaviour {
  
     public float shotInterval = 0.2f; // interval between shots
     public Rigidbody bulletPrefab; // drag the bullet prefab here
  
     private float shootTime = 5.0f;
     private List<Transform> targets;
     private Transform selectedTarget;
     private Transform myTransform;
     private Transform bulletSpawn;
     private int speed = 10;
         
     void Start(){
       targets = new List<Transform>();
       selectedTarget = null;
       myTransform = transform;
       bulletSpawn = transform.Find ("bulletSpawn"); // only works if bulletSpawn is a turret child!
     }
  
     void OnTriggerEnter(Collider other){
       if (other.tag == "Enemy"){ // only enemies are added to the target list!
         targets.Add(other.transform);
       }
         
     }
  
     void OnTriggerExit(Collider other){
       if (other.tag == "Enemy"){
         targets.Remove(other.transform);
       }
     }
  
     void TargetEnemy(){
       if (selectedTarget == null){ // if target destroyed or not selected yet...
         SortTargetsByDistance();  // select the closest one
         if (targets.Count > 0) selectedTarget = targets[0];    
       }
     }
  
     void SortTargetsByDistance(){
       targets.Sort(delegate(Transform t1, Transform t2){ 
         return Vector3.Distance(t1.position, myTransform.position).CompareTo(Vector3.Distance(t2.position, myTransform.position));
       });
         
     }
  
     void Update(){
       TargetEnemy(); // update the selected target and look at it
       if (selectedTarget){ // if there's any target in the range...
         transform.LookAt(selectedTarget); // aim at it
         if (Time.time >= shootTime){ // if it's time to shoot...
         Rigidbody bullet = (Rigidbody)Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
                 Physics.IgnoreCollision( bullet.collider, collider ); 
     
             
                 bullet.AddForce(transform.forward*speed); // shoot in the target direction
           shootTime = Time.time + shotInterval; // set time for next shot
         }
       }
     }
 }
avatar image Chronos-L · Mar 22, 2013 at 02:16 AM 0
Share

Like a actual bullet, you need to propel it with a huge amount of force in a short amount of time, like a controlled explosion in a actual gun.

You controlled the type of force applied to the bullet by using Force$$anonymous$$ode. By default, the AddForce() use Force$$anonymous$$ode.Force, that is good for a continuous force, not a sudden force ( or impulse force ).

Try: bullet.AddForce( bullet.forward * impluseForce, Force$$anonymous$$ode.Impulse );

You need to set the impulseForce to a reasonable amount, just play with the value.

I am not sure it bullet.forward if equivalent to transform.forward, but you can use whatever that works.

avatar image greg1992 · Mar 22, 2013 at 02:41 AM 1
Share

Disregard the above problem. I have messed about with the code some more and it works! =) can't thankyou enough.

I'm pretty sure that also leads me onto a whole new problem =p enemies using colliders (which i can't take of due to the movement system i'm using) messing up the bullet destroy code.

But i'll have a think of that myself, thanks again mate

Show more comments

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

11 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

Related Questions

Collision detection with overlap sphere 1 Answer

Distribute terrain in zones 3 Answers

Why are my projectiles facing the wrong way? 1 Answer

Multiple Cars not working 1 Answer

Produce Collision Though Code 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