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
0
Question by mrapple · Jan 20, 2012 at 10:00 AM · rotationinstantiateplaneflight

Firing a rocket - flight problem

Hey, trying to instiate a rocket, but at the moment, it's just spawning hundreds and hundreds of rockets without me even pressing the mouse, it nearly crashes unity if I don't stop playmode.

     using UnityEngine;
 using System.Collections;
 
 public class RocketLauncher : MonoBehaviour {
 
     public GameObject thingToSpawn;
     
     void Update () {
         if(Input.GetKeyDown(KeyCode.Space));
         {
         Instantiate(thingToSpawn, transform.position, transform.rotation);
         }
     }
 
 }

The problem with the flight mode is that I've got a small script setup, it banks left and right with ease along the Z axis, and it rotates on the X forwards and backwards, but if I rotate it along the Z 90degreas, it won't rotate on the X at all.

(Using relative torque.)

Comment
Add comment · Show 2
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 aldonaletto · Jan 20, 2012 at 11:44 AM 0
Share

Is this script attached to the rocket prefab? If so, maybe the newly created rocket "sees" space pressed and create a new one, which will create another clone etc. The flight problem may be caused by the famous gimbal lock: when rotating 90 degrees around z, x aligns with y, and rotation around x becomes impossible (it depends on how you're doing the rotation).

avatar image mrapple · Jan 21, 2012 at 12:45 AM 0
Share

Is there a way to get around the glimbal lock?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bicko · Jan 20, 2012 at 03:32 PM

You've got a semicolon at the end of your if statement, so Unity thinks the statement has ended and then Update() sees this lovely little Instantiate command to run every frame. Simple problems are the hardest to spot!

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 mrapple · Jan 21, 2012 at 12:45 AM 0
Share

Aaha, thank you. It's always one small little thing.

avatar image
0

Answer by Ranger-Ori · May 07, 2012 at 08:39 AM

When you script with GetKeyDown, it means that as long as you press the key, it keeps instantiating. You have to put an Yield function in order to "pause" the spawning of your rockets. It also seems that you should apply forces to the rocket in order to make it fly.

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

7 People are following this question.

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

Related Questions

Create plane from 2 Vectors of a symmetry line segment 1 Answer

Rotation troubles 2 Answers

Shoot an object and have it move based on rotation 1 Answer

Instantiate not working 2 Answers

Spawning a plane in front of an FPS player? 0 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