Jump to content
Lorenz94

Spawning Simple Objects at position

Recommended Posts

Hello,
I'm having issues on spawning Simple and Super-Simple objects at a given position. I tried to troubleshoot the thing, but I can't find out what's wrong.

 

I'm spawning custom compositions at random positions. Normal objects spawn well, but simple objects "get lost" near [0,0,0]. If all objects get spawned as normal (so using createVehicle, not createSimpleObject), no issues at all.

What's going on:

Spoiler

//Position relative to composition' center, retrieved from a loop of all objects
private _position = getArray (_x >> "positionInfo" >> "position");
private _position = [_position select 0, _position select 2, _position select 1];

///// ///// ///// /////

//Tried both, same result

//Simple object creation
private _object = createSimpleObject ["myClassName", [0,0,10000]];
_object enableSimulationGlobal false;

//Or

//Super Simple objects creation
private _data = ["myClassName"] call BIS_fnc_simpleObjectData;
private _object = [_data, [0,0,10000], 0, false, true] call BIS_fnc_createSimpleObject;

_object enableSimulationGlobal false;

///// ///// ///// /////

//Later on, once found the position
_object setPosWorld _myObjectPos;

private _pos = getPosWorld _object;
_pos set [2, getTerrainHeightASL _pos];
_object setPosWorld _pos;

_object setDir _myDir;

_object enableSimulationGlobal true;

 

Any idea on what can be wrong? Thank you!

 

EDIT: The snippet is intended to show how I retrieve an object' position from the sqe file, the code I tried to spawn the said object as "simple" and how I position it on the map. The positioning works with not-simple objects, while keeps simple objects near the spawn position (as you can see, [0,0,10000]). So I started this topic to kindly ask if anyone has got a similar experience and how to deal with simple objects creation. Thanks.

Share this post


Link to post
Share on other sites

There is another way to do this.

Place say, 5 compositions across the map.  Place them manually in the editor.

 

That implies you start the mission at one of 5 places at random and then patrol towards the appropriate composition.

 

At each of the 5 places that you start, place a trigger and the trigger runs a script. So you have to write 5 scripts.

If you begin at location 1 then  run script 1

If you begin at location 2 then  run script 2

If you begin at location 3 then  run script 3

If you begin at location 4 then  run script 4

If you begin at location 5 then  run script 5

 

 

Script 1 says:  delete compositions 2,3,4,5

Script 2 says:  delete compositions 1,3,4,5

Script 3 says:  delete compositions 1,2,4,5

Script 4 says:  delete compositions 1,2,3,5

Script 5 says:  delete compositions 1,2,3,4

 

And so it is, if you start at location 3 for example, composition 3 is the only one remaining on the map.

 

Share this post


Link to post
Share on other sites

?? The topic is nothing near to your reply, sorry to say!

The snippet shows how I create simple objects and the question is how to avoid simple objects created via script not being set at their position! The problem is not about gameplay logic, I'm *not* asking how to setup a mission to be played. The problem is only related to a single simple object placement, that seems, at least with my flow, to not work as expected.

Share this post


Link to post
Share on other sites

 

_object enableSimulationGlobal false;

There's no point to disable/enable simulation for Simple Objects

//Later on, once found the position
_object setPosWorld _myObjectPos;

private _pos = getPosWorld _object;
_pos set [2, getTerrainHeightASL _pos];
_object setPosWorld _pos;

_object setDir _myDir;

Why did you do this while you want to place it to the pre-defined position?

 

 

_object setPosWorld _position;
_object setDir _myDir;

I don't see the code is correct because it's broken (as it seems, at least in the post).

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Lorenz94 said:

 

 Normal objects spawn well, but simple objects "get lost" near [0,0,0]. If all objects get spawned as normal (so using createVehicle, not createSimpleObject), no issues at all.

What's going on:

  Hide contents


//Position relative to composition' center, retrieved from a loop of all objects
private _position = getArray (_x >> "positionInfo" >> "position");
private _position = [_position select 0, _position select 2, _position select 1];

///// ///// ///// /////

//Tried both, same result

//Simple object creation
private _object = createSimpleObject ["myClassName", [0,0,10000]];
_object enableSimulationGlobal false;

//Or

//Super Simple objects creation
private _data = ["myClassName"] call BIS_fnc_simpleObjectData;
private _object = [_data, [0,0,10000], 0, false, true] call BIS_fnc_createSimpleObject;

_object enableSimulationGlobal false;

///// ///// ///// /////

//Later on, once found the position
_object setPosWorld _myObjectPos;

private _pos = getPosWorld _object;
_pos set [2, getTerrainHeightASL _pos];
_object setPosWorld _pos;

_object setDir _myDir;

_object enableSimulationGlobal true;

 

Any idea on what can be wrong? Thank you!

 

EDIT: The snippet is intended to show how I retrieve an object' position from the sqe file, the code I tried to spawn the said object as "simple" and how I position it on the map. The positioning works with not-simple objects, while keeps simple objects near the spawn position (as you can see, [0,0,10000]). So I started this topic to kindly ask if anyone has got a similar experience and how to deal with simple objects creation. Thanks.

 

 

It's difficult to follow you with all local variable names: _pos... _position... _myObjectPos...

imho    _position = getArray (_x >> "positionInfo" >> "position"); doesn't mean anything. getArray should apply to a config (like getArray (configFile >> "CfgVehicles" >> "Thing" >> "threat")) but perhaps your _x embeds some configFile /cfgClasses... We cannot check that here.

 

Anyway, createSimpleObject needs a positionWorld   while createVehicle needs a usual position  That's probably the reason why you can't replace createVehicle by createSimpleObject (or contrary) without changing the position mode.

So, check if all your _local variables are defined when using them, and check the return value of all your positions.

 

 

Share this post


Link to post
Share on other sites

Thank you for your replies. The snippet it's just pseudo-code, not the actual set of functions of course, I simply summarized the steps I took in a very list-like manner to show the logic behind the process. 

 

@POLPOX - The same function is used to spawn normal and simple objects, so that's why there's also enableSimulationGlobal. You're right about being pointless on simple objects!

@pierremgi - But if I'm spawning them on [0,0,0] before actually moving them to their final position, why do those simple object remain on their initial positions? The final position is the result of findSafePos. If the position format is wrong, shouldn't those simple object just disappear under the terrain or spawn at incorrect heights? That's what I can't understand!

Thanks!

Share this post


Link to post
Share on other sites

Pass...  Now, findSafePos...  How can we help you with hidden codes?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×