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 jarccc7788 · Jan 14, 2013 at 03:59 PM · javascriptprojectile

spell hit rigidbody

i made this spell casting script and i want it to hit other rigidbodys how do i do that here is the scrip

 var spell : Transform;
 
 function Update () 
 {
   if(Input.GetButtonDown("Fire2"))
   {
     var magic = Instantiate(spell, GameObject.Find("spawnPoint").transform.position, 
     Quaternion.identity);
     magic.rigidbody.AddForce(transform.forward * 2000);
   }
 }

here is the script on the fireball

 var ParticlePrefab : GameObject;
 function OnCollisionEnter(collision : Collision)
 {
      : Instantiate(transform.position, transform.rotation, ...);
      Instantiate(ParticlePrefab, transform.position, transform.rotation);
      Destroy(gameObject);
 }
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 Meater6 · Jan 14, 2013 at 04:13 PM 0
Share

Please, format your script. It's quite difficult to read, as you may have seen. Click the spot where you want to place your code, then click the button with binary on it. Then copy/paste. This will improve your chances to get the right answer. Good spelling doesn't hurt too! ;)

Oh, and I retagged your question, to somewhat more suitable tags. Despite its frequency, "help" is not a good tag.

avatar image Meater6 · Jan 14, 2013 at 06:32 PM 0
Share

Thank you :). Now I will see if I can help...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Meater6 · Jan 14, 2013 at 08:28 PM

Ok, I think I noticed a few problems in your scripts.

  1. Instantiating a transform makes an empty GameObject. You do this in your firing script. I'm pretty sure thats not what you want to do. Instantiate a GameObject Instead like so: var spell : GameObject; and then later var magic = Instantiate(spell, spawner.position, spawner.rotation);.

  2. You use GameObject.Find, without assigning it. Its much more efficient (in CPU cycles), to have var spawner : Transform;, instead of "GameObject.Find("spawnPoint")". Even if you ever have to find a GameObject, its preferable to use GameObject.FindWithTag.

  3. You use Quaternion.Identity instead of the rotation of the spawner. This makes it always look forward, even if say, whatever is using the spell, is facing sideways.

  4. I see "`: Instantiate(transform.position, transform.rotation, ...);`" I hope thats not your real script, because that will most certainly not work.

I think those are bugs that are in your script. I may have missed some, unfortunately, as there are many. I do hope you get your script working right.

Good Luck!

Comment
Add comment · Show 2 · 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 jarccc7788 · Jan 22, 2013 at 08:58 PM 0
Share

it works now it was something i have done on the rigidbody i was shooting and thanks for help. by the way can you help me with a spell system like dishonered

avatar image jarccc7788 · Jan 22, 2013 at 09:03 PM 0
Share

thank you for help and i found out what was wrong i was on the rigidbody i was shooting. by the way can you help me with a spell system like dishonored

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

9 People are following this question.

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

Related Questions

Launching a Projectile to a Raycast 1 Answer

Problem when creating a projectile for a weapon. (FIXED) 1 Answer

2D Space Shooter Instantiating bullet question 1 Answer

Shooting Projectiles 1 Answer

Object reference not set to an instance of an object 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