Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
6
Question by e-bonneville · Apr 12, 2010 at 12:43 AM · rotationphysicsdrag

Realistic rotation of flying arrow?

The title says it all. How would I realistically simulate rotational physics? For example, I have an arrow. When I shoot it, it should go up and then rotate towards the ground as it's falling. However, when I shoot it now, it'll go up, and then fall back to the ground, all the while maintaining the same rotation. This doesn't look good at all. I thought perhaps drag was the key, but it doesn't fit my lock, so to speak. How would I do this? 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

5 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by KvanteTore · Apr 12, 2010 at 07:10 AM

One way of solving would be to make the arrow out of two rigidbodies, a tip and a tail, connected with a FixedJoint. If you then make the tip heavier than the tail, and/or have a larger drag on the tail, I believe you should get the desired rotating with tip towards ground effect.

Comment
Add comment · Show 5 · 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 e-bonneville · Apr 12, 2010 at 01:54 PM 0
Share

Ah... That makes sense. Thanks for the reply.

avatar image e-bonneville · Apr 12, 2010 at 02:04 PM 0
Share

It works, but now I have to instantiate an arrowhead as well. I tried putting them both in an empty gameObject, but that didn't work either. Any ideas?

avatar image madmike6537 · Nov 15, 2012 at 05:27 AM 0
Share

I would love to know how to use this method, but I have the same problem with instantiating two arrow peices. They fall apart even though they are in a prefab.

avatar image RoyMallis · May 28, 2015 at 10:09 AM 0
Share

Late response but this took me a while, this was exactly the same answer I came around to. You'll wan to put a Fixed joint component on the rear "drag" child object and have the rest of the arrow as the "connected body". You then just set the drag of of the child object higher than the other.

avatar image Scrubberinus · Jul 25, 2016 at 04:17 PM 0
Share

Sorry for necroing this, but I've tried this and my arrows rotate the way I want them. However, I'm having trouble with the instantiation of my arrows. If I am not setting their velocity, when the appear on screen, their rotation is the original prefab rotation for like a frame or two before rotating to the desired rotation. When I am setting the velocity though, the arrow stays in the rotation it's in in those two frames. All of this does not happen if I remove the rigidbody. Any ideas why it does this?

avatar image
22

Answer by runevision · Apr 12, 2010 at 10:02 AM

The arrow rotates in real life due to wind resistance that pushes on the arrow in a way that is specific to the shape of the arrow. That is overly complicated to simulate "realistically" in a game, so it's much easier to just rotate the arrow such that the tip points in the direction of movement:

myArrow.transform.forward =
    Vector3.Slerp(myArrow.transform.forward, myArrow.rigidbody.velocity.normalized, Time.deltaTime);
Comment
Add comment · Show 9 · 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 KvanteTore · Apr 12, 2010 at 11:30 AM 2
Share

Agree. This is probably the easiest solution. If the arrow can change velocity abruptly (e.g. hit a wall and then fall straight down), it could possibly be improved by lerping the orientation towards the orientation.

avatar image runevision ♦♦ · Apr 12, 2010 at 01:03 PM 0
Share

Good point. I changed the example code so it slerps the direction.

avatar image e-bonneville · Apr 12, 2010 at 01:58 PM 0
Share

That's a great idea. However, it didn't work. The arrow just rotated towards the top center of my screen. Any ideas?

avatar image runevision ♦♦ · Apr 12, 2010 at 04:36 PM 0
Share

If the forward direction of your arrow is something else than +z you need to change the code accordingly. For example, if the arrow points in the +y direction, you need to use transform.up ins$$anonymous$$d of transform.forward.

avatar image e-bonneville · Apr 12, 2010 at 05:03 PM 0
Share

Oh, I see. Well, I'm shooting an arrow, and I want the tip to point in the direction it's falling, so what if it's falling downward? Will it still work?

Show more comments
avatar image
9

Answer by tylo · Sep 30, 2010 at 05:36 AM

This is how I do it.

void FixedUpdate(){
    if(rigidbody.velocity != Vector3.zero)
     rigidbody.rotation = Quaternion.LookRotation(rigidbody.velocity);  
}
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 hellowill89 · Jul 11, 2020 at 09:12 PM 0
Share

This one is actually my favorite. The movement seems like it belongs in FixedUpdate rather than Update.

avatar image
0

Answer by StephanK · Apr 12, 2010 at 07:41 AM

Another way that should work is to adjust the arrows rigidbody.centerOfMass so that it is closer to the tip.

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 KvanteTore · Apr 12, 2010 at 11:27 AM 0
Share

would that work? Both gravity and drag works on the center of mass, and does not provide any torque.

avatar image
0

Answer by Ryder · Jun 06, 2010 at 11:02 PM

Actually, it's easy to do with one line of code. In this case, + .y is the direction of travel for the object (as if your arrow was modeled with the tip up). don't give the rigidbody any drag You just add a relative impulse to get it going... then

function FixedUpdate(){

// add a force like to drag, opposite the direction of travel, and apply it aft of the center of mass, typically (0,0,0) rigidbody.AddForceAtPosition(rigidbody.velocity * -.1,transform.TransformPoint(0,-.25,0));
}

If this creates too much drag, one can add a constant relative Force to the arrow to offset it

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 AaronC · Sep 30, 2010 at 03:29 AM 0
Share

That makes arrows do loop-de-loops

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

7 People are following this question.

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

Related Questions

drag object including free rotation 0 Answers

How do drag and angular drag interact? 2 Answers

Clamp Bike Rotation 0 Answers

Rotating a Rigidbody with Physics 1 Answer

Simulating the graphics of a rolling 3D ball in a 2D game 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