x


Instantiation with inheriting velocity problem

while (count < numberofBouncyBalls) 
{   
     var eplosive1 : Rigidbody = Instantiate(bouncyExplosive, transform.position, transform.rotation);

     eplosive1.rigidbody.velocity = rigidbody.velocity;
     eplosive1.angularVelocity = rigidbody.angularVelocity;

     count = count + 1;
 }

Alright I am attempting to use this for something I am making where a single rigidbody bouncy ball splits into 3 or as many as I want other bouncy balls, and it is easy to simply instantiate an amount of them however they simply start bouncing up and down boaringly, I am trying to use this to give each ball the velocity and such of the ball they are technically separating from but for some reason I get this error.

InvalidCastException: Cannot cast from source type to destination type. Separate+Start$20+$.MoveNext () (at Assets\WeaponScripts\Separate.js:20)

I am not to experienced with javascript so I was wondering if anyone could point me towards the reason why this is happening or a fix to my problem, cheers.

more ▼

asked Nov 18 '10 at 05:56 AM

QuestionBro 1 gravatar image

QuestionBro 1
11 1 1 2

Top of your code sample was clipped off in the format, don't forget checking the post previewer when posting , yes I'm nitpicky , but it helps with the Q&A process

Nov 18 '10 at 08:05 AM Proclyon
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

recommand

more better fucntion

rigidbody.AddForce(velocity, ForceMode.VelocityChange);

rigidbody.AddTorque(angularVelocity, ForceMode.VelocityChange);

more ▼

answered Nov 18 '10 at 08:11 AM

jameslee0227 gravatar image

jameslee0227
79 2 2 9

This isn't needed. There's a reason the velocity and angularVelocity properties are read/write. Original code fine.

Jan 20 '11 at 12:49 AM Jonathan Czeck
(comments are locked)
10|3000 characters needed characters left

Probably your bouncyExplosive prefab does not have a Rigidbody component attached to it, so when you cast it to Rigidbody and assign to variable eplosive1, it spits out that error.

more ▼

answered Jan 20 '11 at 12:48 AM

Jonathan Czeck gravatar image

Jonathan Czeck
51 4 5 9

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1798
x1683
x318

asked: Nov 18 '10 at 05:56 AM

Seen: 1150 times

Last Updated: Jan 20 '11 at 02:36 AM