Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
About snap to grid size objects

experimentlghost
Registered User
Quote
2016-04-11 10:35:12

Hi every coppercube lovers,
I asked a question about snap to grid the objects during the game like sea battle games and nikholaus send me that script.
I says lots of thanks for share this script.
I'm sharing here for maybe it helps someone.





function snap(value, gridSize, roundFunction){
if (roundFunction === undefined) roundFunction = Math.round;
return gridSize * roundFunction(value / gridSize);
}

var global_gridSnapValue = 5;

function snapNodeToGrid(s)
{
var position = ccbGetSceneNodeProperty(s, "Position");

var moveobjX = snap(position.x, global_gridSnapValue);
var moveobjY = snap(position.y, global_gridSnapValue);
var moveobjZ = snap(position.z, global_gridSnapValue);

ccbSetSceneNodeProperty(s,"Position",moveobjX,moveobjY,moveobjZ);
ccbUpdateSceneNodeBoundingBox(s);
}

---------------------------------------------------------

Then, to snap a node with for example the name 'ship' to grid, do it like
that:

snapNodeToGrid(ccbGetSceneNodeFromName("ship"));






jaimezegpi
Registered User
Quote
2016-04-11 23:10:46

Nice..!!
Logic tested ,
var matrix_pos_n=gridSize * roundFunction(pos_n / gridSize);

works super..


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internation?l" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact