- Home /
How to change the scale of an instantiated rigid body
Hi - I'm trying to change the size of the projectiles fired from a launcher but it won't let me apply localScale to a rigid body. This is my code:
var projectile : Rigidbody;
var objectSizeMax: int =.5;
function Update()
{
if( Input.GetButtonDown( "Fire1" ) ){
var numRandom:int = (Random.value*objectSizeMax)+0.5;
var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation ) ;
//instantiatedProjectile.localScale = Vector3.one * numRandom; //make the projectile a random scale...NOT WORKING
}
};
I Think that the problem is you objectSize$$anonymous$$ax, because it's a int with a value of 0.5, if you want decimal values, use float ins$$anonymous$$d, and set the projectile var from Rigidbody to Transform in both cases, or use: instantiatedProjectile.transform.localScale
I'm not sure what you mean change the projectile var from Rigidbody to Transform - I need it to be a rigid body so it will collide with things, right?
Yeah that's the problem - both the the float and the missing "transform". Thanks!
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Will Goldstone turtorial; wall of cubes not normal, just exploding. 1 Answer
You should never scale the parent of a rigidbody 3 Answers
Values are changing but the scale of sprite no. 1 Answer
Convert rigidbody velocity to home in on target when it gets close 1 Answer