# ProblemFailing to spawn a vessel at the desired position [solved, use clbkPreStep]

#### N_Molson

##### Addon Developer
Addon Developer
Donator
Hello,

Still on the Tianwen Mars project, I'm trying to spawn the parts jettisoned by the lander during the descent (shell and parachute, heatshield...). So I searched for a code sample doing this and I came with the below piece of code. It sort of works, but it seems it isn't accurate enough. The discarded vessel is created like 10 meters above my lander, and it seems tilted at a 90° angle. I'd expect it to spawn exactly where my vessel is, and oriented the same way. Right now, it looks crappy. So, what am I missing there ? ? My lander is oriented like a capsule, -Z axis is towards the heatshield +Z axis is towards the parachute. It is a rather small vessel so I don't see where that 10 meters (or more) offset is coming from...

C++:
void TIANWEN_LANDER::SpawnObject(void)
{
VESSELSTATUS2 vs;
vs.flag = 0;
vs.version = 2;

char name[256];
VECTOR3 sofs = { 0, 0, 0 };        // Seperation offset
VECTOR3    sdir = { 0, 0, 1 };        // Seperation direction
double    svel = 0;                // Separation velocity[/COLOR]

// Get vessel status structure
VECTOR3 rofs;
GetStatusEx(&vs);
Local2Rel(sofs, vs.rpos);
GlobalRot(sdir, rofs);
vs.rvel += rofs * svel;

// Create descent stage as seperate vessel
strcpy(name, GetName());
strcat(name, "-Shell");
oapiCreateVesselEx(name, "Tianwen_shell", &vs);
}

#### jedidia

##### shoemaker without legs
Addon Developer
The discarded vessel is created like 10 meters above my lander, and it seems tilted at a 90° angle. I'd expect it to spawn exactly where my vessel is, and oriented the same way.
Rotation and position of a vessel when spawning in landed state depend on the first three touchdown points!

#### asbjos

##### tuanibrO
Addon Developer
Are you spawning the vessel from PostStep? I've experienced the same offset in position when spawning from there. Moving it to PreStep fixed it for me.

As for the rotation, is it precisely 90°? If so, it could be you have forgotten that Orbiter uses a left-handed coordinate system, so you may have to swap y and z.

#### N_Molson

##### Addon Developer
Addon Developer
Donator
Are you spawning the vessel from PostStep? I've experienced the same offset in position when spawning from there. Moving it to PreStep fixed it for me.

You're the best ! That was it, now it works perfectly. The rotation issue was related.

Rotation and position of a vessel when spawning in landed state depend on the first three touchdown points!

In this particular case you have "vs.flag = 0;" which means "in flight". Landed state is 1 (or the now famous "special" -10 value).

### Similar threads

Replies
2
Views
632
Replies
10
Views
1K
Advanced Question Spawning a landed vessel
Replies
7
Views
2K
Replies
8
Views
1K
Replies
0
Views
946