Hi,
I have been trying for sometime to adapt a code to work with the physics engine. I want to automaticly calculate the velocity to apply to an object via phent_addvelcentral, considering the distance to be covered between the object position and a target vector in a way that the object moves and accurate aims the target.
I need this calculation for stopped and moving objects and targets. I have this code that doesnt use the PE:
Code:
var vSpeed;
var vTarget[3] = 0,0,0;
var distBetweenObjTarget[3];
action testObj
{
var vAccel;
var vMove;
var iSpeed = 2;
while(1)
{
//turn towards target
vec_set(temp,vTarget.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);
//calculate distance between obj and target
distBetweenObjTarget = vec_dist(my.x,target.x);
//calculate velocity to apply
vAccel.x = iSpeed * distBetweenObjTarget[0];
vAccel.y = iSpeed * distBetweenObjTarget[1];
vAccel.z = iSpeed * distBetweenObjTarget[2];
vec_accelerate(vMove, vSpeed, vAccel, 0.5);
c_move(my, vMove, nullvector, glide);
wait(1);
}
}
I´ve ran several tests but i cant find a way to do this with the physics engine, because i think the ODE solver gives different results from physics formulas and euler approximations.
So, using the PE how can this be done?
Should i retrieve the velocity and angular velocity via phent_getvelocity and phent_getangvelocity and use that information, or in the other hand, i need to use the mass, friction and other values to be calculated like acceleration?
I really appreciate some help on this matter.
Thanks.