|
Post by Karvy on Apr 9, 2016 0:05:57 GMT
Hi everyone! I've tried to make scripted rigidBody imposters and then create skinmesh imposters that follow the rigidbodies. I've tried to get the rigidbody imposter's location using iObjectImpostersGet and then use iObjectImpostersSet to set skinmesh imposter position. But nothing happened so I need a little help here :/ ImposterProblem.3dr (112.99 KB)
|
|
|
Post by n_iron on Apr 10, 2016 6:11:44 GMT
Hi Karvy below is a script I used for a Duck shoot I never finished. I don't expect you so use the script as is but it contains all the necessary parts to get your character moving.
To get the birds all fly together I used Boids flocking algorithm script.
n_iron
float nx,ny,nz; float prev_err,SetPoint,offSet,pid; float speed,pDist,dist; float power; Vector3 boidVector; Quaternion q1,q2; /// boid ID index int Boid=1; /// rigidBody object int boidRBObject=OBJ_154; /// skinMesh object int boidSMObject=OBJ_132;
void Main(){ if(iInitializing()){ // initalise positions iObjectImposterShow(boidSMObject,Boid); iObjectImposterGet(boidRBObject,Boid,q1,boidVector); nx=boidVector.x; ny=boidVector.y; nz=boidVector.z;
offSet=0.0f; /// skinmesh y offset SetPoint=3.5; } power=IN_112; // boid location iObjectImposterGet(boidRBObject,Boid,q1,boidVector); // rigid body imposter
dist=iVectorLength(boidVector-Vector3(nx,ny,nz));
speed=((pDist-dist)/0.0166); // dataBus1.value 2 - using speed for error point if(speed<0){ speed=0; }
/// boid new vector dataBus2.value1 if(dist < 15 && IN_110==Boid){ nx=IN_66; ny=IN_67; nz=IN_68; }
/// Character Movement and Direction /// now I have to set new position iQuaternionLookAt(q2,Vector3(nx,ny,nz)-boidVector,Vector3(0,1,0)); //(pCenter-v1) boidVector.y+=offSet; iObjectImposterSet(boidSMObject,Boid,q1,boidVector); int force=pidControl(speed, SetPoint); forceApply(boidRBObject,force,q2,Boid); // apply force to rigid body
string debug="Boid 1\r pid "+pid+"\rpower "+power+"\rspeed "+speed+"\rdist "+dist; //\r nx "+nx+"\rny "+ny+"\rnz "+nz; iPrint(debug,-12,11,OBJ_0);
pDist=dist;
Vector3 screevV; i3DLocationToScreen(screevV,boidVector ,OBJ_88); //iPrint(debug,screevV.x,screevV.y,OBJ_0); }
/// Apply force to an object with the value of the velocity void forceApply(int pickedObject,int velocityForce,Quaternion forceOrientation,int i){ Vector3 pickedLocation,targetLocation,velocityDirection; velocityDirection = DirectionVector(forceOrientation); iVectorLengthSet(velocityDirection,velocityDirection,velocityForce); iObjectImposterForceApply(pickedObject,i,velocityDirection,Vector3(0,0,0.5)); }
/// direction vector for force object Vector3 DirectionVector(Quaternion q){ Vector3 direction; iVectorRotate(direction,Vector3(0,0,1),q); return direction; }
/// walk power control float pidControl(float velocity,float mph){ float err; float Kp=0,Ki=0,Kd=0,Df,Dt; //,pid; Df=0; Dt=0.001666; err=(mph-velocity); Kp=power*2*err; // 1 increases rise time - large values (10eg.) Ki=0.05*(err*Dt); // 0.001 increases the rise time - small values (1 to 0.9eg.) Kd=0.0033*((err-prev_err)/Dt); // 0.09 decreases over shoot - small values (1 to 0.001eg.) if(err<0){ pid=1; }else{ pid=(Kp+Ki+Kd+Df); } prev_err=err; return pid; } /// set vector length Vector3 lengthVectorSet(Vector3 v1,float L){ Vector3 rV; iVectorLengthSet(rV,v1,L); return rV; }
|
|
|
Post by TinSoldier on Apr 11, 2016 3:30:48 GMT
Hi everyone! I've tried to make scripted rigidBody imposters and then create skinmesh imposters that follow the rigidbodies. I've tried to get the rigidbody imposter's location using iObjectImpostersGet and then use iObjectImpostersSet to set skinmesh imposter position. But nothing happened so I need a little help here :/ Karvy replace your script with this and you should see how to do it. Vector3 rigidbodyLoc; Quaternion rigidbodyRot;
void Main() {
if(iInitializing()){ iObjectImpostersCreate(OBJ_0,2); iObjectImpostersCreate(OBJ_22,2); iObjectImposterSet(OBJ_22,0,rigidbodyRot,Vector3(10,0,0)); iObjectImposterSet(OBJ_22,1,rigidbodyRot,Vector3(20,0,0)); } if(iDeinitializing()){ iObjectImpostersDestroy(OBJ_0); iObjectImpostersDestroy(OBJ_22); }
for(int i=0; i<2; i++){ //Get RigidBody imposter's position iObjectImposterGet(OBJ_22,i,rigidbodyRot,rigidbodyLoc);
//Set that position to the Skinmesh imposters iObjectImposterSet(OBJ_0,i,rigidbodyRot,rigidbodyLoc); } }
|
|
|
Post by Karvy on Apr 11, 2016 18:23:58 GMT
Hi guys and thank you very much for replying my post. All what I needed was the for() looping statement. Anyways the duck shooting scripts is very useful!
And thank you TinSoldier your script helped me to solving my problem but have you tested it before? It gives me problems with the 3d models so I had to modify it a bit.
|
|
|
Post by TinSoldier on Apr 12, 2016 15:54:50 GMT
Hi guys and thank you very much for replying my post. All what I needed was the for() looping statement. Anyways the duck shooting scripts is very useful! And thank you TinSoldier your script helped me to solving my problem but have you tested it before? It gives me problems with the 3d models so I had to modify it a bit. yes i used the 3dr project you supplied, just replace the original script with mine. If your still having problems, are you using 3drad v7.22 don't what else would give you problems cause i modified your script in 3drad to produce my script. Heres the project ready to run... ( it uses default objects ) if this still doesnt work for you, reinstall 3drad v7.22 over top of your current 3drad folder. I can only guess you may have a corrupt installation. ( this is a pretty basic program, there shouldn't be any issues running it ) dl.dropbox.com/s/p577hq3evhpyaci/ImposterProblemA.3dr?dl=1Edit: One other idea, once loaded, check the object properties to make sure they show up in the project before running. cant think of any other possible problems.
|
|