Skip to main content
1-Visitor
Apr 15, 2020 1:10 AM UTC
Solved

Moving multiple models

I'm using the code below to move multiple models. The issue I'm having is they all have different starting locations. So they appear to 'jump' to that Y coordinate, and then move up. Is there a way to have the function inherit the original value and then move up?

 

$scope.posChange1 = function() {
$scope.app.params['ClipMovement']+=0.0001;
}

$scope.moveClip = function() {
$scope.app.params['ClipMovement'] = 1.329;
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
};

micahAnswer
1-Visitor
Apr 19, 2020 10:39 PM UTC

That works perfectly. Another issue I'm having is looping the movement.

I've tried:

 

$scope.moveClip = $interval(function() {
for(var i=0; i< 3; i++){
$scope.view.wdg[Objects[i]].y=start[i];
}
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
}, 1000);

 

Where moveClip(); is bound to a click function of a button. But the loop starts when the view is loaded rather than when the button is clicked.

 

(Also, how do you add code to post in that box?)

5 replies

14-Alexandrite
Apr 15, 2020 10:35 AM UTC

Hi,

 

you can write your objects in a list and loop through it like this:

 

var Objects =["3DGauge-1","3DGauge-2","3DGauge-3"];

$scope.posChange1 = function() {
 for(var i=0; i< 3; i++){
	$scope.app.view.Home.wdg[Objects[i]].y+=0.0001;
 }
}

$scope.moveClip = function() {
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
};
Translate
micah1-VisitorAuthor
1-Visitor
Apr 16, 2020 11:50 PM UTC

This isn't suitable for my situation because if I run that function twice it will incrementally add from the last position. I'd like the models to move from each of their original positions, and if the function is run again, go back to the original and then move up.

 

Is there a way to call back the original 'y' position of all the models?

Translate
14-Alexandrite
Apr 17, 2020 4:46 AM UTC

You can store them in an array on startup and change the values to the original each time you call the function.

Something like this:

var Objects =["3DGauge-1","3DGauge-2","3DGauge-3"];
var start = []; 
$scope.$on("$ionicView.loaded", function (event) {
 for(var i=0; i< 3; i++){
	start.push($scope.app.view.Home.wdg[Objects[i]].y);
 }
});

$scope.posChange1 = function() {
 for(var i=0; i< 3; i++){ 
	$scope.app.view.Home.wdg[Objects[i]].y+=0.0001;
 }
}

$scope.moveClip = function() {
 for(var i=0; i< 3; i++){
	$scope.app.view.Home.wdg[Objects[i]].y=start[i];
 }
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
};
Translate