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?

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

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

@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.

-simply add an empty object at the head of the spear prefab ( call it head)
-add transform variable to reference the position of the head

  • applay a weight force (point down) at the head postion
void FixedUpdate(){
m_rigidbody.AddForceAtPosition(-transform.up* headWeight, head.position);
}