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 Pranoy-Parimal · Apr 01, 2014 at 07:53 AM · physicsprojectilearrowforces

Projectile motion of an arrow after applying force

I have been banging my head against the wall for days, trying to solve this problem but I am not getting any solution. I am trying to achieve a real projectile motion of an arrow after applying a force to the arrow of certain magnitude in a particular direction. Actually I want the arrow to follow a projectile motion with the head of the arrow going upward for first half of the projectile motion & the head of the arrow facing downward for the second half of the projectile motion. For clear vision see the attached video below:

https://www.youtube.com/watch?v=VwHcqheekt8

I have taken a sprite with the Sprite Renderer of an arrow & a Rigidbody 2D attached to it. The mass of the RIgidbody 2D attached to the arrow sprite has a mass of 0.0001, Linear & Angular drag of 0.05 , gravity scale of 0. There are two empty objects,ArrowHead & ArrowTail, inserted inside this arrow sprite. Bothe these empty objects are having RigidBody 2D attached to these. ArrowHead object has got a Mass of 3 while ArrowTail object has got a mass of 1. After button click the a force is applied to the arrow sprite in (ArrowHead - ArrowTail) direction. But the empty objects attached to the arrow sprite do not move synchronously with the arrow after applying force.

Any help regarding this will be highly appreciated.

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 senad · Apr 01, 2014 at 10:22 AM

This might not help you directly with your problem, but have you considered solving it without the physics engine?

As you can see, it takes quite some fiddling to get it right. Computing the trajectory and rotation for an arrow can be done in the code without the physics engine.

Unless you have some compelling reason to use physics, the other aproach might be easier to implement, change and debug.

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 Pranoy-Parimal · Apr 01, 2014 at 10:39 AM 0
Share

Thanks for the reply ...

But can you guide me through this without using the physics ... It will be very helpful ...

avatar image senad · Apr 01, 2014 at 03:02 PM 0
Share

From the starting point you calculate a trajectory like described here: http://en.wikipedia.org/wiki/Trajectory

Then you get a function f(t). With this function you can calculate the position at a given time t. Every frame now you calculate the position of the arrow and move it to the position from the trajectory-function.

I would advise you to read this stuff up. You will then have full understanding und control over your code and the behaviour of the arrow, trajectory, etc.

:)

avatar image
0

Answer by jamesflowerdew · Apr 01, 2014 at 10:36 AM

As above I'd be tempted to apply gravity without the physics

pseudocode below:

pArrowMomentum+=new Vector(0,MyGravity*Time.deltaTime,0);

transform.LookAt(transform.position+pArrowMomentum);

transform.position+=pArrowMomentum*Time.deltaTime;

you could apply the above to rigidbody.velocity if you're desperate to use physics but with fast objects like arrows I'd be really tempted to use raycasts, as arrows/bullets can pass through physics objects if their speed is high enough.

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 robertbu · Apr 01, 2014 at 03:44 PM

For most arrow situations, you want the arrow to follow the velocity. Assuming 2D sprite in which the front of the arrow points right when the rotation is (0,0,0), you can do:

 var dir = rigidbody2D.velocity;
 if (dir != Vector3.zero) {
     angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
     transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
 }
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 Pranoy-Parimal · Apr 03, 2014 at 05:07 AM 0
Share

@robertbu Thanks for the help. It really worked like a charm. I really appreciate your help...

avatar image ammar2unify · Jun 30, 2015 at 07:26 AM 0
Share

Thnx robertbu.

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

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

Related Questions

Projectile(Arrow) angle during flight is not realistic 1 Answer

Questions about a Bow and Arrow FPS setup 1 Answer

A node in a childnode? 1 Answer

Calculate Height of Trajectory : Unity3d 1 Answer

Vector3 and power 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