Throwing An Arrow -- I want it to rotate naturally

Official forum for the Chipmunk2D Physics Library.
Post Reply
privateson
Posts: 3
Joined: Thu Jul 16, 2009 10:52 am
Contact:

Throwing An Arrow -- I want it to rotate naturally

Post by privateson »

Hi,
I am trying to throw an arrow or spear to the sky. At the same time, I would expect it to spin or rotate naturally.
This is how I create the arrow in the following way..

Code: Select all

        mass = 700;
	elasticity = 0.9;
	friction = 5.0;
	collisionType = 1;
	initialBodyPosition = cpv(60, 100.0); 
	
	layers = 1;
	r =  cpv(0,0);
	
	body = cpBodyNew(mass, INFINITY);  	
	body->p = initialBodyPosition; 

	cpVect verts_line[] = {
		cpv(-2,-40),
		cpv(-2, 40),
		cpv( 2, 40),
		cpv( 2,-40),
	};
	
	shape = cpPolyShapeNew(body, 4, verts_line, cpv(0, 35));   //cpCircleShapeNew(body, 20.0, cpvzero); 
	shape -> layers = layers;
       //something like this.....
And I throw the arrow like this:
cpBodyApplyForce(k, cpv(7000,11000), cpv(500,30));
OR
cpBodyApplyImpulse(k, cpv(70000,110000), cpv(5000,300));

So the arrow does move, but it won't rotate or spin at all.

Does anyone know what I should do?
Or any example?

Thanks :>
solmead
Posts: 2
Joined: Mon Jun 29, 2009 8:22 am
Contact:

Re: Throwing An Arrow -- I want it to rotate naturally

Post by solmead »

The "body = cpBodyNew(mass, INFINITY); " part is wrong. The infinity needs to be replace with the center of mass.

INFINITY needs to be replaced with:

cpMomentForPoly(mass, 4, verts_line, cpv(0,35));
(Might need to be -35 instead)
PeskyJ
Posts: 19
Joined: Fri Apr 24, 2009 4:24 pm
Location: Reading, UK
Contact:

Re: Throwing An Arrow -- I want it to rotate naturally

Post by PeskyJ »

To get this effect using pure physics you will need to:
a) Adjust the centre of gravity (CoG) of your object to be closer to the front (the arrow-head);
b) Apply a wind resistance to the object NOT at the centre of gravity, but at it's physical centre (the shaft centre).

I suggest using a joint to connect the arrow-head object to the shaft object, the arrow-head object will then add weight to the front and move the centre of gravity closer to the front. You will have to play with the weight ratios, start with equal weights for the head and shaft. Then to apply wind resistance, apply a small force opposite and proportional to the velocity to the shaft object. This will create a moment about a point somewhere between the head and shaft centre. In addition to being proportional to the velocity, this force should be scaled down according to the angle between the velocity and the vector from the shaft CoG and the head CoG (the line along the spear shaft) - this way the force will reduce to zero when the shaft is in line with the direction of flight.

This should keep the shaft trailing behind the head which will give the rotation you desire.

J
Games games games... I love games. Check out my games: [url]http://www.tinyplay.com/games.html[/url]
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests