Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Dibes · Nov 20, 2012 at 12:27 AM · c#rotationphysicsrigidbodydynamic

How to make a dynamic bow shot and the arrow to curve and turn correctly when shot?

What i mean by dynamic bow shot is that i can just use a prefab as the model and the code takes care of "animation" for how far the arrow is drawn back and power is based on that. I have a basic shooting script that will instantiate and create a raycast for collision detection. Here is the code i have for my current arrow object.

 public class ArrowScript : MonoBehaviour {
 
     // The objects transform
     private Transform myTransform;
     //Speed of bullet
     public float arrowSpeed = 1f;
     // Prevents bullet from causing further harm once it hits something
     private bool expended = false;
     // Casts a ray in front of bullet to see if it will hit a recognizable collider
     private RaycastHit hit;
     // The range of the ray currently 1.5 units in front of bullet
     public float rayRange = 1.5f;
     // Name of what the bullet collides with
     public string colliderName = "Floor";
     // Lifespan of projectile
     public float expireTime = 5;
     // Attaching the explosion particle effect to the script
     public GameObject arrowHit;
     
     // Use this for initialization
     void Start () {
         //Assigns myTransform to whatever this script is attached to's transform.
         myTransform = transform;
         // Initializes the co-routine (ienumerator). That way it starts when the object is created
         StartCoroutine(DestroyMyselfAfterSomeTime());
     }
     
     // Update is called once per frame
     void Update () {
         // Makes it move in the up direction (y) times bulletspeed and it is smoothed out by Delta time, keeps it at a constant speed.
         myTransform.Translate(Vector3.up * arrowSpeed * Time.deltaTime);
         // If the ray hits something and expended is false
         if(Physics.Raycast(myTransform.position, myTransform.up, out hit, rayRange) && !expended) {
             // If what the bullets collides with has the tag...
             if(hit.transform.tag == colliderName) {
                 // Instantiate the bullet hit
                 Instantiate(arrowHit, hit.point, Quaternion.identity);
                 expended = true;
                 arrowSpeed = 0;
                 //Make the bullet stop rendering
                     //myTransform.renderer.enabled = false;
                 //Logs to make sure it has been called
             }
         }
         // Draws a line
         Debug.DrawRay(myTransform.position, myTransform.up, Color.red);
     }
     
     IEnumerator DestroyMyselfAfterSomeTime() {
         // Waits for 5 seconds then continues on in code
         yield return new WaitForSeconds(expireTime);
         Destroy(myTransform.gameObject);
     }
 }

So overall i want to create a bow system that will shoot proportional to how far it is drawn back. I also want the arrow to have a weight and fall towards the ground realistically, possibly using rigid bodies. When i was tinkering with it, the arrow would not rotate with the right torque and i tried adding some via the constant force component.

Thank you for all the help!

Sincerely, Dibes

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

0 Replies

· Add your reply
  • Sort: 

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

Flip over an object (smooth transition) 3 Answers

Configurable Joints pass through colliders 2 Answers

How to make Rigidbody.AddForce less delayed in Unity3D? 0 Answers

Rigidody.velocity = Direction * speed; How to get direction? 1 Answer

How to set a limit for my player rotation ? 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