- Joined
- Feb 2, 2012
- Messages
- 1,667
- Reaction score
- 105
- Points
- 78
about the code I provided before, a check to exclude the "self transportation" of the gateway vessel must be added, since it's checking for all the vessels in the sim, it will check also for himself and its distance from himself will always be 0 and it will start to fly around in a loop until your pc melts down :lol:
---------- Post added at 17:07 ---------- Previous post was at 15:49 ----------
the quick and dirty example works with the following code (in pre or poststep of course), but it's still far to be perfect, it just could be a starting point
from now on have fun
---------- Post added at 17:07 ---------- Previous post was at 15:49 ----------
the quick and dirty example works with the following code (in pre or poststep of course), but it's still far to be perfect, it just could be a starting point
from now on have fun
Code:
for (UINT i=0;i<oapiGetVesselCount();i++)
{
OBJHANDLE hvessel=oapiGetVesselByIndex(i);
if(hvessel!=GetHandle())
{
VECTOR3 rpos,rvel;
oapiGetRelativePos(hvessel,GetHandle(),&rpos);
double distance=length(rpos);
oapiGetRelativeVel(hvessel,GetHandle(),&rvel);
if((distance<2)&&(rpos.z>0)&&(rvel.z<0))
{
VESSELSTATUS2 vs_vessel,vs_other_gate;
memset(&vs_vessel, 0, sizeof(vs_vessel));
memset(&vs_other_gate, 0, sizeof(vs_other_gate));
vs_vessel.version=2;
vs_other_gate.version=2;
VESSEL *v;
v=oapiGetVesselInterface(hvessel);
v->GetStatusEx(&vs_vessel);
OBJHANDLE h_other_gate;
char myname[16];
char GateA[16];
sprintf(myname,GetName());
sprintf(GateA,"Gate_A");
if(strcmp(myname,GateA)==0)
{
h_other_gate=oapiGetVesselByName("Gate_B");
}else{
h_other_gate=oapiGetVesselByName("Gate_A");
}
VESSEL *v_other_gate;
v_other_gate=oapiGetVesselInterface(h_other_gate);
v_other_gate->GetStatusEx(&vs_other_gate);
vs_vessel.rbody=vs_other_gate.rbody;
vs_vessel.rpos=vs_other_gate.rpos;
vs_vessel.vrot=vs_other_gate.vrot;
vs_vessel.arot=vs_other_gate.arot;
VECTOR3 outvel=_V(rvel.x,rvel.y,rvel.z);
VECTOR3 rofs;
GlobalRot(outvel,rofs);
vs_vessel.rvel.x=vs_other_gate.rvel.x+rofs.x;
vs_vessel.rvel.y=vs_other_gate.rvel.y+rofs.y;
vs_vessel.rvel.z=vs_other_gate.rvel.z+rofs.z;
v->DefSetStateEx(&vs_vessel);
}
}
}