Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by QuestionBro 1 · Nov 18, 2010 at 05:56 AM · rigidbodyinstantiatevelocity

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Proclyon · Nov 18, 2010 at 08:05 AM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by jameslee0227 · Nov 18, 2010 at 08:11 AM

recommand

more better fucntion

rigidbody.AddForce(velocity, ForceMode.VelocityChange);

rigidbody.AddTorque(angularVelocity, ForceMode.VelocityChange);

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jonathan Czeck · Jan 20, 2011 at 12:49 AM 0
Share

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

avatar image
0

Answer by Jonathan Czeck · Jan 20, 2011 at 12:48 AM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

instantiate finding upstream velocity 1 Answer

Rigidbody.velocity works diffrent on cloned object 0 Answers

Multiplying something.forward using a variable doesn't actually multiply, but multiplying by a number does. 1 Answer

Trouble with rb.Addforce(transform.foreward) 3 Answers

Resume movement of instanced object relative to the original after instantiation. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges