Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by serpentwitch · Apr 19, 2015 at 01:09 AM · rigidbodyrandomspace shooterangularvelocity

step 10 space shooter asteroid random rotation not working

I have followed this script but it still won't rotate

 using UnityEngine;
 using System.Collections;
 
 public class RandomRotator : MonoBehaviour
 {
     public float tumble;
 
     void Start ()
     {
         rigidbody.angularVelocity = Random.insideUnitSphere * tumble; 
     }
 }


I've also changed it to "GetComponent" code because I'm using the new 5.0 script. but still doesn't work.

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DoTA_KAMIKADzE · Apr 19, 2015 at 01:10 AM

 GetComponent<Rigidbody>().angularVelocity = Random.insideUnitSphere * tumble;

Also make sure your tumble value is > 0.

Comment
Add comment · Show 2 · 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 serpentwitch · Apr 19, 2015 at 04:03 AM 0
Share

yes, done that, still not rotating.

well, I searched and tried a few alternative and this one works pretty well I think. Though I still don't understand why the code on the training won't work with me.

  private float maxRotationSpeed; 
  private Vector3 rotSpeed;  
     
     
     void Start()
     {
         maxRotationSpeed = 50;
         rotSpeed = Random.insideUnitSphere * maxRotationSpeed;
     }
     
     void Update()
     {
         GetComponent<Transform> ().Rotate (rotSpeed * Time.deltaTime);
     }
 



avatar image DoTA_KAMIKADzE · Apr 19, 2015 at 11:30 AM 0
Share

Well there are 2 possible problems then:

1)You forgot to add Rigidbody component to your asteroid which holds your RandomRotator.

2)You forgot to set your tumble value to something else than 0. Either via code or via inspector (because you use public I think you set it in inspector).

Or both of the above.

avatar image
10

Answer by AuggoDoggo · Jul 08, 2015 at 06:18 AM

I had the same problem, double checked everything, followed every suggestion in this thread and then I started fooling around with the Random.insideUnitSphere and replaced it by creating a vector3 with all of its values being "Random.value". Nothing worked... except for capitalizing my Start function...

void Start()

NOT

void start()

I feel dumb and defeated sometimes but then I realize I learned another simple lesson today that I won't be needing again tomorrow...

I'm sorry if this is not the answer to OPs problem, but perhaps it will help someone with my problem.

Comment
Add comment · Show 5 · 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 Qandeel · Jul 19, 2015 at 06:12 PM 0
Share

You bet it did :D

avatar image DizzyDog · Aug 28, 2015 at 07:21 AM 0
Share

I had the same problem, Ctrl through the forums to find this..... Thanks!

avatar image EnclaveZombie · Sep 02, 2015 at 02:06 PM 0
Share

Thank you sooooo much!

avatar image StealthMacaw · Oct 26, 2015 at 06:57 PM 0
Share

This actually solved my problem without me having to look far, thanks!

avatar image cynrode · Aug 11, 2017 at 06:49 AM 0
Share

Thank you for this.

avatar image
0

Answer by brandoncomputer · May 23, 2015 at 02:26 PM

using UnityEngine; using System.Collections;

public class RandomRotator : MonoBehaviour {

 public float tumble;

 void Start()
 {
     GetComponent<Rigidbody>().angularVelocity = Random.insideUnitSphere * tumble;
 }

}

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
avatar image
0

Answer by $$anonymous$$ · Oct 23, 2015 at 05:04 AM

Simple fix trick. Check Kinematic on the asteroid rigid body. Save scene then project. close unity. reopen unity and uncheck Kinematic. Make sure the code looks like this.

 using UnityEngine;
 using System.Collections;
 
 public class RandomRotator : MonoBehaviour
 {
     public float tumble;


Also make sure to go ahead and tag the asteroid as "hazard." private Rigidbody rb;

     void Start ()
     {
         rb = GetComponent <Rigidbody> ();
         rb.angularVelocity = Random.insideUnitSphere * tumble;
     }
 }




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 Vijayhattarki · Oct 13, 2018 at 12:55 PM 0
Share

The above fix works but the asteroid position is also changing in all the direction, how can i fix it?

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to set rigidbody velocity and angularVelocity to Vector3.zero over time? 1 Answer

i wanna set max velocity, max angular velocity to joint 0 Answers

Hinge Joint issue 0 Answers

Angular Velocity not correctly rotating objects 1 Answer

Falling meteorites from the sky - C#,Falling meteorites | C# 1 Answer


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