I'm using the sync framework and I have a script that instantiates an object where ever you tap on the screen. I have also attached physics to this object.
Part of the sync framework is the syncTransform script which you can attach to an object to have their position/scale/rotation stored.
I need to do this for each of the instantiated objects. Anyone know how to do this via scripting?
Here's my spawn code:
/`/ -----JS CODE-----
//@input Component.Camera camera
//@input Asset.ObjectPrefab myPrefab
//@input Component.ScriptComponent syncTransform
script.createEvent("TouchStartEvent").bind(onTouchStart);
function onTouchStart(e){
if(script.camera){
var rndInt2 = Math.floor(Math.random() * 180);
var rndInt = Math.floor(Math.random() * 180);
var rndInt3 = Math.floor(Math.random() * 180);
var degrees = rndInt2;
var axis = new vec3(rndInt2,rndInt,rndInt3)
var rotationToApply = quat.angleAxis(radians, axis);
// Convert degrees to radians
var radians = degrees * (Math.PI / 180);
var touchPosition = e.getTouchPosition();
var worldPosition = script.camera.screenSpaceToWorldSpace(touchPosition, 100);
var mySceneObject = createObjectFromPrefab();
mySceneObject.getTransform().setWorldPosition(worldPosition);
mySceneObject.getTransform().setWorldScale(new vec3(0.5,0.5,0.5));
mySceneObject.getTransform().setWorldRotation(quat.angleAxis(radians, axis));
var tommy = mySceneObject.createComponent("Physics.BodyComponent");
tommy.shape = Shape.createBoxShape();
tommy.shape.size = new vec3(35,35,8);
tommy.massOrDensity =10.0;
}
}
function createObjectFromPrefab(){
if(script.myPrefab){
var instanceObject = script.myPrefab.instantiate(script.getSceneObject());
return instanceObject;
}
else{
return undefined;
}
}`