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 Leonard Kropf · Jun 12, 2010 at 08:16 PM · rotationjavascript

space flying system

hey guys i want to make a flight system for spaceships that can be rotated over all axes like in the unity game Phoenix final
and it should be move foreword if i press a button and it should stopp if i press a button

i have scripted something

var rotateSpeed = 3.0;

function Update () { var controller : CharacterController = GetComponent(CharacterController); //Rotate arond y transform.Rotate(0, Input.GetAxis ("Horizontal") rotateSpeed, 0); //Rotate arond x transform.Rotate(0, Input.GetAxis ("Vertical") rotateSpeed, 0); }

@script RequireComponent(CharacterController)

but its only rotating over 1 axe where is the mistake

and one axe is missing and the forward force

thanks for answers

sry for bad english(im german)

Update

thx at all but the c# code wont work but i have still one question

and it should be move foreword if i press a button and it should stopp if i press a button

to add a force

i would be happy if you could answer that

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Eric5h5 · Jun 12, 2010 at 10:38 PM

You wouldn't use a character controller for a flying game in any case. Character controllers are only for games like Doom/Quake/Unreal, since among other things they remain upright at all times.

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
2

Answer by Alai · Jun 13, 2010 at 03:39 AM

The way I do it is to have a seperate function to handle rotation, which I refactored out from my input script into a more general ship script when I had to handle AI rotation of the ship:

(my code is in C#, but the idea is the same)

public void rotateShip(float xAxis, float yAxis) { float turnLimit = 0.5f; //float minTurnLimit = 0.02f;

 if ((0 != xAxis) || (0 != yAxis))
 {
     //Debug.Log("Moving: " + this.gameObject.name + " to (" + xAxis + "," + yAxis + ")");
 }

 if (xAxis > turnLimit) { xAxis = turnLimit; }
 if (yAxis > turnLimit) { yAxis = turnLimit; }
 if (xAxis < -turnLimit) { xAxis = -turnLimit; }
 if (yAxis < -turnLimit) { yAxis = -turnLimit; }

 //if (xAxis < minTurnLimit) { xAxis *= 2; }
 //if (yAxis < minTurnLimit) { yAxis *= 2; }
 //if (xAxis > -minTurnLimit) { xAxis *= 2; }
 //if (yAxis > -minTurnLimit) { yAxis *= 2; }

 float rotateX = yAxis * Time.deltaTime * this.turnXRate;
 float rotateY = xAxis * Time.deltaTime * this.turnYRate;
 float rotateZ = 0;

 if (
     (0 != rotateX) ||
     (0 != rotateY) ||
     (0 != rotateZ)
   )
 {
     this.transform.Rotate(rotateX, rotateY, rotateZ);
 }

}

One important thing to note here is the line:

float rotateX = yAxis * Time.deltaTime * this.turnXRate;

because it ensures a constant rotation rate by multiplying with Time.deltaTime, and it seperates the turn rate out into something that can be easily modified per ship type.

Stylistically, I also just seperate those input calls out into variables right from the get-go:

float inputXAxis = Input.GetAxis("Horizontal");
float inputYAxis = Input.GetAxis("Vertical");

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
1

Answer by StephanK · Jun 12, 2010 at 10:32 PM

It's only rotating around the y-axis, because both Rotate functions use only values for y. The second rotate should probably use the x value instead.

tranform.Rotate(Input.GetAxis("Vertical") * rotateSpeed, 0, 0);
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

Rotate character to the moving direction problems? 2 Answers

A little help with this camera script please? 3 Answers

Object is the wrong way around 1 Answer

Character Rotation - Script not functioning correctly 1 Answer

"Perfect" Free Rotation Method? (like Blender) 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