|
Re: newton
[Re: ventilator]
#113122
11/04/07 17:55
11/04/07 17:55
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
Quote:
with moving characters
i can say, l'm just moving simple objects, called character ;-)))
|
|
|
Re: newton
[Re: VeT]
#113123
11/04/07 18:17
11/04/07 18:17
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
okay, here it is Code:
void MHonforceandtorque(NewtonBody* body) { float mass, ixx, iyy, izz; NewtonBodyGetMassMatrix(body, &mass, &ixx, &iyy, &izz); NewtonBodySetAutoFreeze (MH.NewtonChar, 0); vec_set(temp_vec,vector(MH.keyX*100, MH.keyY*100,-mass*5)); vec_rotate(temp_vec,MH.model.pan); NewtonBodySetForce(MH.NewtonChar,vectorf(temp_vec.x,temp_vec.y,temp_vec.z)); // damping NewtonBodySetLinearDamping (MH.NewtonChar, 0.9); // rotating NewtonBodySetOmega(MH.NewtonChar, vectorf(0,0,-MH.mouseX*5)); // // speed limit NewtonBodyGetVelocity(MH.NewtonChar, velocity); temp_vec2.x = velocity[0]; temp_vec2.y = velocity[1]; temp_vec2.z = velocity[2]; // NewtonBodySetVelocity(MH.NewtonChar,vectorf(temp_vec2.x,temp_vec2.y,temp_vec2.z)); }
function player_init() { // MH.model = me; MH.handler = handle(MH.model); MH.NewtonChar = newton_addentity(MH.model, 10, NEWTON_SPHERE, MHonforceandtorque); NewtonBodySetMassMatrix (MH.NewtonChar, 10.0, 10.0, 10.0, 10.0); NewtonBodySetAngularDamping (MH.NewtonChar, vector(100,100,100)); }
PS:i use omega to move entity exactly as mouse moves ;-)
Last edited by VeT; 11/04/07 18:24.
|
|
|
Re: newton
[Re: VeT]
#113124
11/04/07 18:36
11/04/07 18:36
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2002
Posts: 7,441
|
some things i noticed: - the mass matrix already gets set in newton_addentity(). - be careful with vector()/vectorf(). newton doesn't work with vars. - i think if your "character" is a rolling sphere then it doesn't really make sense to rotate your steering force like that. or does setomega block all rotation? it's hard to say... maybe someone else has ideas.
|
|
|
Re: newton
[Re: VeT]
#113126
11/04/07 19:40
11/04/07 19:40
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
debug shows that sphere looks in right position... red line is looking straight ahead, so problem isnt here so, i'd try to explain problem more exactly: - i press W, body moves forward... - if i allow body to stop, and then press A, body strafes normal - BUT if i dont allow it(for example, press W, press A, unperss W), body moves forvard-left... it's looks like forward force still working, but Code:
vec_set(temp_vec,vector(MH.keyX*100, MH.keyY*100,-mass*5));
and MH.keyX = (key_pressed(17) - key_pressed(31)); so, force =0, if W isnt pushed... thats main trouble :-( anyway, ventilator, thank you very much for help... i'd add you to credits :-D
Last edited by VeT; 11/04/07 20:09.
|
|
|
|