Jump to content
celludriel

Laptop won't stick to table

Recommended Posts

I'm tyring to spawn a table with laptop in my script  but the output always ends up with a floating laptop on top of the table :(

_table = createVehicle ["Land_CampingTable_F", _spawnPosition, [], 0, "can_collide"];
_pc = [_spawnPosition] call MCSRV_fnc_spawnMobileComputer;
_pc attachTo [_table, [0,0,0.8]];

I've been playing with the last parameter from 0 to 1 but the results are nearly all the same.  Is there a way to calculate it exactly ?

Share this post


Link to post
Share on other sites

Hello celludriel

 

I think what you need is this:

_pc attachTo [_table, [0,0,<height in float value>]];

The thrid paramter defined how high the laptop will be attached to the table.

 

Play around witht that paramter until the height matches the hight you want for the laptop.

 

 

For example:

_pc attachTo [_table, [0,0,0.2]];

Would make the lapop beeing attached way lower than your old code.

 

If you still need for explanation about this feel free to message me.

 

 

Regards Arkensor

  • Like 1

Share this post


Link to post
Share on other sites

Well I got it quite right with this.  I wonder though if there isn't a more efficient way, some way to calculate the max height of the table and then use that to calculate the float.  I rather work with relative values then literals.

Share this post


Link to post
Share on other sites

Why don't you use 3D editor to place your objects ? its also has a snap tool

and you need to use also in init field of object:

 

this enableSimulation false; this allowDamage false; otherwise it with fall from the table !

Share this post


Link to post
Share on other sites

Why don't you use 3D editor to place your objects ? its also has a snap tool

and you need to use also in init field of object:

 

this enableSimulation false; this allowDamage false; otherwise it with fall from the table !

 

Well you don't have the full context.  What I'm doing is the following

 

- Spawn truck with action deploy

- deploy action

  - spawn campfire on place of truck

  - 90 degrees on ten meters from campfire spawn a container

  - 270 degrees on ten meters from campfire spawn a table with laptop on top

  - remove truck 

  • Like 1

Share this post


Link to post
Share on other sites

_spawnPosition = player getPos [ 3, getDir player ]; 
 
_table = createVehicle ["Land_CampingTable_F", _spawnPosition, [], 0, "can_collide"]; 
_pc = createVehicle ["Land_Laptop_unfolded_F", _spawnPosition, [], 0, "can_collide"]; 
_maxZTable = boundingBoxReal _table select 1 select 2; 
_maxZPC = boundingBoxReal _pc select 1 select 2;  
_pc attachTo [_table, [0,0,( _maxZTable + _maxZPC ) ]];
Adding half the height of each objects bounds will give you the correct height.

Does not always look correct due to the way the laptops shadows behave, but if you add/subtract a small amount to this value like 0.005 and look at the laptops side you will see that it is as near as dammit.

  • Like 1

Share this post


Link to post
Share on other sites
_spawnPosition = player getPos [ 3, getDir player ]; 
 
_table = createVehicle ["Land_CampingTable_F", _spawnPosition, [], 0, "can_collide"]; 
_pc = createVehicle ["Land_Laptop_unfolded_F", _spawnPosition, [], 0, "can_collide"]; 
_maxZTable = boundingBoxReal _table select 1 select 2; 
_maxZPC = boundingBoxReal _pc select 1 select 2;  
_pc attachTo [_table, [0,0,( _maxZTable + _maxZPC ) ]];
Adding half the height of each objects bounds will give you the correct height.

Does not always look correct due to the way the laptops shadows behave, but if you add/subtract a small amount to this value like 0.005 and look at the laptops side you will see that it is as near as dammit.

 

 

Thanks seems boundingBoxReal was the funciton I was looking for.  I just need to wrap my  head around adding the max height of the pc to the max height of the table.  Doesn't that mean I would be putting the pc on top of it's max height ?  I'm sure this sollution here works I just don't understand yet how ti works ?  I would have imagined putting it at _maxZTable would have been enough ... to be investigated

Share this post


Link to post
Share on other sites

Take all the vertices that make up the model and find its extremes mins and maxs in x,y,z.
The bounding box [0,0,0] will be in the middle of this cuboid shape.
All axis mins/maxs will be of the same length. e.g min z is the same length as max z just one is negative value and the other positive respectively.
So from the center of the table plus it Max Z is the top of the table.
Placing the PC here would be placing the PCs [0,0,0] the center of its bounds.
So we add half its height by using Max Z as it is a positive value.
We could use its Min Z but as we are going up we know its Max is a positive value and is the same length as Min Z and saves having to write something like.

_maxZTable = boundingBoxReal _table select 1 select 2; 
_minZPC = boundingBoxReal _pc select 0 select 2;  
_pc attachTo [_table, [0,0,( _maxZTable + abs _minZPC ) ]];

Turning its negative Min Z into a positive value.

bounds.png

  • Like 1

Share this post


Link to post
Share on other sites

Thanks larrow you deserve a medal for this explaination , clear and crips , I understood it completly

Share this post


Link to post
Share on other sites

You can use setVehiclePosition to place objects on the surface:

private _relX = 0; //laptop relative x on table
private _relY = 0; //laptop relative y on table
private _tablePos = player getRelPos [3, 0];
private _table = "Land_CampingTable_F" createVehicle [0,0,0];
private _pc = "Land_Laptop_unfolded_F" createVehicle [0,0,0];
_table setPos _tablePos;
_pc setVehiclePosition [_tablePos vectorAdd [_relX, _relY, 1000], [], 0, "CAN_COLLIDE"];
_pc attachTo [_table];
  • Like 2

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

×