• 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 pankul · May 13, 2013 at 09:32 PM · shootingprojectile

Shooting in a Projectile for Archery game

Hello All...i am new to Unity. I am working on a game in which player shoots an arrow in the air at some angle and with fixed velocity. I am not able to simulate this in Unity. Every time I shoot, the arrow goes in the straight line instead of following projectile. Can anyone please help me with this?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by $$anonymous$$ · Jun 26, 2015 at 05:30 PM

https://www.assetstore.unity3d.com/en/#!/content/35524

Check this out..

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
avatar image
0

Answer by rutter · May 13, 2013 at 09:35 PM

The Rigidbody manual page may be helpful. Do you have a rigidbody attached to the arrow? If not, it won't be affected by Unity's physics engine.

If you want a Rigidbody to fall with gravity, make sure that "use gravity" is enabled in its inspector settings. If you want something a little bit fancier, the constant force component can be helpful. If you want to get fancier, still, you can always code up a custom component to manage to acceleration and velocity any which way you like.

Comment
Add comment · Show 4 · 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 pankul · May 13, 2013 at 10:09 PM 0
Share

Thanks $$anonymous$$exallon and Rutter for your replies. I have already applied a rigidbody and constant force and gravity also, but the problem is that the arrow/bullets move straight ins$$anonymous$$d of falling at a particular point. I was thinking of calculating the range of the projectile and then move the bullet following the projectile motion equations. But i dont know how to do that in Unity. Please help.

avatar image robertbu · May 13, 2013 at 10:18 PM 1
Share

@pankul - I converted your Answer to a comment. Answers are reserved for attempts to answer your question. By putting answers in comments, you run up the number of answers making it less likely that you will get more answers.

As for your problem, you should post your code. I suspect you are adding velocity each frame. For this kind of model, what you want is a set velocity a single time at the begging (or better yet a Rigidbody.AddForce()) and then let gravity take over. There have been other arrow questions on this list, so do a Google search. Plus you will likely have to do something like this to keep the arrow pointed in the correct direction:

 transform.LookAt(rigidbody.velocity);
avatar image pankul · May 13, 2013 at 10:26 PM 1
Share

$$anonymous$$y code for the player is :

public class cube$$anonymous$$ove : $$anonymous$$onoBehaviour {

 public float playerSpeed;
 public GameObject CapsulePrefab;//shoot script is attached  
                                       to this prefab
 public float angle = 45.0f;
 public GameObject clone;
 public float force = 1000.0f;

 
 // Update is called once per frame
 void Update () 
 {
     // to move the player(cube)
     float amtTo$$anonymous$$ove = Input.GetAxis("Horizontal")*playerSpeed*Time.deltaTime;
     transform.Translate(Vector3.right*amtTo$$anonymous$$ove);
     
     
 
     if (Input.GetButtonDown("Fire1"))
     {
         clone = Instantiate(CapsulePrefab,transform.position,Quaternion.Euler(0,0,angle)) as GameObject;
         clone.rigidbody.AddForce(Vector3.forward*force);
     }
 }
 
 }

And my code for the arrow (shoot script) is :

public class shoot : $$anonymous$$onoBehaviour {

 public float speed=5.0f;
 
 void Update ()
 {
     float amtTo$$anonymous$$ove = speed*Time.deltaTime;
     transform.Translate(Vector3.up*amtTo$$anonymous$$ove);
     
 }
 

}

Please check the code and suggest me the changes.

avatar image robertbu · May 14, 2013 at 02:32 AM 0
Share

Delete lines 5 and 6 for in the arrow/shoot class, and add my LookAt() line from my comment above. Typically rigidbodies and Transform.Translate() don't mix well (and often result in missed collisions).

avatar image
0

Answer by MyUnitydream · May 25, 2019 at 06:32 PM

Hi to all my first course published on Udemy.com

2D Archery Game In Unity3d https://www.udemy.com/2d-archery-game-in-unity-3d/?couponCode=MYFIRSTLESSON

For the first 200 people we consider 36% discount. Dicsount Code: MYFIRSTLESSON

In the next month other chapters wil be published

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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 avatar image

Related Questions

Cannon shoots in wrong direction with unrealisic Physic 1 Answer

Shooting in 2 dimensional games 2 Answers

Gun Fire, sparks on Collision 1 Answer

Shooting projectiles in 2D world 2 Answers

How to avoid speed change in bullets while moving? 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