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
0
Question by basil3 · Dec 30, 2017 at 12:39 PM · c#physicsrigidbody3dprojectile

Throwing a Spear

Hi,

I have been trying to find a way of getting a spear throw to correctly 'dip' at the head and fly correctly. I have found that using the following code should work:

 public void ReleaseSpear () {

     rigidB.useGravity = true;
     rigidB.AddForce (gameObject.transform.forward = 
 Vector3.Slerp(gameObject.transform.forward, rigidB.velocity.normalized, Time.deltaTime * 5)* 18000);
     gameObject.transform.parent = null;

 }


Basically all this does is turn gravity on, adds force to the gameobject and unparents it from the hand.

The spear model has the blue (forward) axis pointed forwards and yet it still flys tail 'heavy' and lands in the ground tail down?

Can anybody see why this is happening?

alt text

An image of the spear once launched? Notice the tail dipping and not the head?

alt text

spear.jpg (274.7 kB)
untitled.jpg (250.1 kB)
Comment
Add comment · Show 1
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 nt314p · Dec 31, 2017 at 10:26 PM 0
Share

Wow nice game (although might have a smaller target audience)!

1 Reply

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

Answer by sparkzbarca · Dec 30, 2017 at 06:26 PM

have you tried making the tip of the spear and the shaft of the spear separate objects, make the spear head the parent, the shaft the child and increase the mass of the spear tip? This is in fact of course why spears actually fly the way they do physically and you are trying to emulate that with a physics engine.

If you dont want to modify the model you can just create an empty gameobject with a lot of mass and put it in the center of the spear tip and parent to that

Comment
Add comment · Show 3 · 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 basil3 · Dec 30, 2017 at 10:11 PM 0
Share

@sparkzbarca - Thanks for the reply - I have tried this (and again to see if I did something wrong) but again it just behaves in the same manner.

I have also tried to to set the Quaternion Rotation to the rigid body velocity (to make the spear point towards the destination vector over time) but again this does not seem to work (weird behaviour were the spear travels sideways and then moves inwards over time). I thought this was working and perhaps the axis were off but after trying multiple options it still behaved the same.

I have also explored trying to offset the centre of mass of the gameobject but again this did not work.

Ste.

avatar image sparkzbarca basil3 · Dec 30, 2017 at 10:39 PM 0
Share

void FixedUpdate(){ if(rigidbody.velocity != Vector3.zero) rigidbody.rotation = Quaternion.LookRotation(rigidbody.velocity);
}

credit:

https://answers.unity.com/questions/14899/realistic-rotation-of-flying-arrow.html

The general consensus seems to be the key is both mass in the tip and DRAG in the back. You can physics that with empty game objects with larger drag co-efficents but most people think that's really overcomplicating it and your better to code simluate it than actually go full on physics.

avatar image basil3 sparkzbarca · Dec 31, 2017 at 10:17 AM 0
Share

You sir are a legend.

Thank you - I couldn't understand why the code was not working as it all looks fine. I had even attempted the Quaternion.LookRotation from that thread but didn't put it into a fixed update.

So the now the spear flies perfectly. The code was this:

 public void ReleaseSpear () {

     gameObject.transform.parent = null;
     rigidB.useGravity = true;
     rigidB.AddForce (gameObject.transform.forward * 30000);
     Vector3.Slerp(gameObject.transform.forward,rigidB.velocity.normalized, Time.deltaTime * 2);
     rigidB.ResetCenterOf$$anonymous$$ass();

 }


 void FixedUpdate () { 
     
     if (rigidB.velocity != Vector3.zero) {
         
         rigidB.rotation = Quaternion.LookRotation (rigidB.velocity.normalized);
     }

 }

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

456 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Fireing a tank projectile. 1 Answer

[Physics] Compensating for Moving/Rotating Terrain 0 Answers

I need the ability to disable the functionality of a Rigidbody without deactivating it's GameObject, removing it, or changing any of it's physics settings 0 Answers

Multiple Cars not working 1 Answer

How to make Rigidbody.AddForce less delayed in Unity3D? 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