- Home /
Spear throwing with HTC Vive
Hi
I'm a beginner in Unity but please bear with me.
I'm playing with Unity and HTC Vive. I've created a simple scene where you can pick up a spear and then throw it. Now the problem is - the physics of the spear don't really match a spear - it rotates around the axis perpendicular to the length of the spear. I was wondering how I can set it up so that the tip has all the weight and it carries the momentum of the throw. I have already tried changing the centre of mass of the RigidBodyObject and that changes the behaviour slightly, but there's still no momentum. The speed and movement of the spear comes only from the Vive controller.
I'll be grateful for your help.
Cheers
Could you give us an image or something like that? I'm having a hard time visualizing what you're describing.
Can you also post a screenshot of how you've got your colliders set up on the spear? Unity calculates weight distribution by the collider setup.
WHAT!? YOU CAN $$anonymous$$A$$anonymous$$E VIVE GA$$anonymous$$ES WITH UNITY!?!
How are you angling the spear when you throw it?
I'm assu$$anonymous$$g you attach it to the transform of your controller until you let go but is it set to be pitched at 35 - 40 degrees or does it's rotation also depend on the controller?
$$anonymous$$ight be worth looking at that if so.
The rotation was caused by the angularvelocity of the controller being passed onto the spear.
Now I'd just like it to angle down as it falls - it's flight is pretty much straight.
Answer by OrbitGames · May 19, 2016 at 07:11 PM
Try Transform.forward = rigidbody.velocity
No, you don't want to manually adjust the rotation of a rigidbody if you can help it. It throws off the physics system.
Even if you restrict the rotation on the rigidbody?
Another idea would be to use AddForceAtPosition on a point on the back of the spear, which adds a force in the opposite direction of the velocity, which would act as drag.
But adding force would alter the thrown arc. Really, the best way to fix physics problems is to think about them from a real-world perspective. I asked to see how the colliders were set up because I think it would be most beneficial to add a new collider to the front that will make the object more front-heavy. Phantom forces often add more harm than good.
Right now the issue is likely that the weight is distributed evenly, which is far from the case in a real-life sphere.
Answer by Taylor-Libonati · May 26, 2016 at 11:14 PM
I would suggest making the center of your transform that has the rigid body be at the tip of the spear and having. Also it could be a problem with the script that is handling the throwing. Did you write your own throwing code or use someone else's?
Yeah the rotation was the fault of the script - I noticed that it passed the controller angular velocity to the object on throw.
I'll try adding more mass to it.
Cheers
Answer by Ivan-WIdyan · Nov 30, 2016 at 07:36 AM
Maybe you can give clamp function for the spear? So it's not rotate many times like in your picture