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 gilgada · Mar 22, 2012 at 12:41 PM · rotationinputautomationcatapultinitiate

Help with initiating an automated sequence

Hi, I have a game in which you control a catapult. Currently the player can rotate the "arm" of the catapult and the game launches the projectile if the arm reaches a certain angle. However, as this is an educational momentum-based game, I need the angle of the catapult arm to affect the projectile's velocity. To get to doing this I need the player to be able to initiate a launch sequence for the catapult arm, storing the rotation of the arm at the point of initiation so it can be used later. The problem I am having is setting up a script for launch. It needs to do the following:

  • Stop accepting input from the up and down arrow keys temporarily as they affect the rotation script

  • Only require the space bar to be pressed once in order to trigger the launch

  • Automate the movement of the arm from whatever rotation it is at, up to the 90 degree mark

The actual trajectory of the projectile is done elsewhere and is initiated when the arm reaches the 90 degree mark in its x axis rotation.

The rotation script for the catapult arm is as follows:

var speed : float = 5.0f; // meters per second function FixedUpdate() { if(Input.GetKey ("up") && transform.rotation.eulerAngles.x < 85) { transform.rotation.eulerAngles.x += speed; } if(Input.GetKey ("down") && transform.rotation.eulerAngles.x > 10) { transform.rotation.eulerAngles.x -= speed; }
}

Any help in setting up the launch sequence script would be greatly appreciated!

Many thanks to such a great community

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

1 Reply

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

Answer by clfischer · Mar 28, 2012 at 10:37 AM

Would this work?

 var launching : bool = false;
 var adjustmentSpeed : float = 5.0f; // degrees per second
 var launchSpeed : float = 100.0f; // degrees per second
 var launchAngle : float; // degrees        

 function Awake() {
     transform.rotation.eulerAngles.x = launchAngle;
 }    

 function FixedUpdate() {    
     if (!launching) { // no launch in progress    
         if (Input.GetKey ("up") && transform.rotation.eulerAngles.x < 85) {    
             transform.rotation.eulerAngles.x += adjustmentSpeed*Time.deltaTime;    
         }
  
         if (Input.GetKey ("down") && transform.rotation.eulerAngles.x > 10) {    
             transform.rotation.eulerAngles.x -= adjustmentSpeed*Time.deltaTime;    
         }    

         if (Input.GetKey ("space")) {   
             launchAngle = transform.rotation.eulerAngles.x;  
             launching = true;    
         }    
     } else { // launch has been initiated    
         if (transform.rotation.eulerAngles.x < 90) { // Swing catapult arm until it reaches 90 degrees.
             transform.rotation.eulerAngles.x += launchSpeed*deltaTime;    
         } else { // Launch projectile when the arm has reached 90 degrees.
             Launch();    
         }   
     }    
 }


 function Launch() {   
     // Eg. Instantiate projectile and give it the appropriate velocity
     // based on the value of launchAngle.
 }




Remember to reset the launching flag to false when you're ready to for the user ta make adjustments and launch again.

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 gilgada · Apr 06, 2012 at 09:32 AM 0
Share

thanks it works great!!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotate object after swipe according to swipe direction 0 Answers

PS3 Analogue Stick Axis Values 1 Answer

Can i change position depending on another object axis? 2 Answers

Rotating object with a mouse movement 0 Answers

Drag object in a circle path 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