It creates random balls, but it determines where it is created. I want to set it manually but the code is not working
`//balls start
for (var i = 0; i < this.balls.length; i++)
{
var ball = this.balls[i];
//var pos = ball.getPosition();
if (pos.y < -10) {
ball.rigidbody.linearVelocity = pc.Vec3.ZERO;
ball.rigidbody.angularVelocity = pc.Vec3.ZERO;
ball.rigidbody.teleport((Math.random() - 0.5) * 30, 5, (Math.random() - 0.5) * 30);
}
}
//balls finish
};
Controller.prototype.ballsspawn = function(){
var ball = this.app.root.findByName(‘Ball’);
// Randomly generated a bunch of balls across the terrain
for (var i = 0; i < this.topsayisi; i++) {
var clone = ball.clone();
this.app.root.addChild(clone);
clone.rigidbody.teleport((Math.random() - 0.5) * 30 , 5, (Math.random() - 0.5) * 30 );
//this.balls.push(clone);
}`
Hello, I have a ball object under the “top2” object in the project and I am duplicating it with the following code.
//initalize function
this.balls = [];
//update function
for (var i = 0; i < this.balls.length; i++)
{
var ball = this.balls[i];
var pos = ball.getPosition();
if (pos.y < -10) {
ball.rigidbody.linearVelocity = pc.Vec3.ZERO;
ball.rigidbody.angularVelocity = pc.Vec3.ZERO;
ball.rigidbody.teleport((Math.random() - 0.5) * 30, 5, (Math.random() - 0.5) * 30);
}
}
Controller.prototype.ballsspawn = function(){
var ball = this.app.root.findByName('Ball');
// Randomly generated a bunch of balls across the terrain
for (var i = 0; i < this.topsayisi; i++) {
var clone = ball.clone();
this.app.root.addChild(clone);
clone.rigidbody.teleport((Math.random() - 0.5) * 30 , 5, (Math.random() - 0.5) * 30 );
this.balls.push(clone);
}
};
The problem is that the balls always spawn in the same location. I want to create for example at “x = -70”. How do I provide this? Where and how do I make any changes to the code?