• 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 FizzyBear · Apr 08, 2012 at 01:58 AM · animationjavascriptparticlessphere

[SOLVED] Shooting from Elemental Staff

Okay, sorry to bug you guys again. If I was to create an elemental staff within a model (it has no firing animation etc) what do I need to do in order to shoot from the staff in the straight line it's been clicked on?

I've attached a Sphere Gameobject as a child of the staff, but I have no idea on what I need to do in order for when I click my mouse that it shoots that sphere.

If you guys have any tutorials, please do tell as I'm actually wanting to learn how Unity works!

Thanks

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
1
Best Answer

Answer by rutter · Apr 08, 2012 at 03:08 AM

You could use Vector3.Lerp() to move the sphere from initial position to target position, over time.

The Unity manual page on prefab instantiation mentions a few methods for firing projectiles. You could look into adapting those to suit your purposes. When example scripts reference a "direction" for the shot, you can provide a direction by subtracting the target position from the shot origin -- this will give you a vector pointing from one position to the other.

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 FizzyBear · Apr 08, 2012 at 09:49 AM 0
Share

Okay, I used that to generate my code, but at the moment it just generates a stationary sphere. Although after trying to uhh.. Implement Vector3.Lerp, I'm kind of flabbergasted.

The code which I came up with is this:

var bullet : Transform;

var target : Transform;

function Update () {

 if ($$anonymous$$otor.toggleCombat$$anonymous$$ode){
     if(Input.Get$$anonymous$$ouseButton(0)){
             var hit: RaycastHit;
         
             if (Physics.Raycast(target.position,target.forward, hit)) {
                 var hitpoint = hit.point;
                 transform.LookAt(hitpoint);
                   var bullet1 : GameObject = Instantiate (bullet , GameObject.Find("spawnPoint").transform.position, UnityEngine.Quaternion.identity);
                 bullet1.transform.rotation = transform.rotation;
                 bullet1.rigidbody.AddForce(transform.forward * 1000);
         }
     }
 }

}

This is after I gave up with Vector3.Lerp. The code ^ just creates a stationary prefab at the 'spawnPoint' of the elemental staff. Any suggestions? :/

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation plays at original position? 1 Answer

How can I tell Unity to wait to do something until after and animation has finished playing? 0 Answers

Change the value of a Key in animation (via code) 0 Answers

How can I tell Unity to wait to do something until after and animation has finished playing? 1 Answer

[SOLVED] Shooting fail (Due to camera setup) 2 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