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 Graeme P · Apr 26, 2011 at 08:06 AM · rotationcharactercontrollercontrolleraxisxbox360

Control object (character) rotation with 360 analogue.

Hi,

I have a game where you are in a sub-sea environment, and fly about in a ship.

Im controling the ship via an xbox 360 controller, using this..

var moveSpeed:float = 1.0; var turnSpeed:float = 1.0; var climbSpeed:float = 0.2; var bouancy:float = 1.0;

function Update ()

{

var DepthControl = Input.GetAxis("Depth");

var horizontalSpeed = Input.GetAxis("Horizontal");

var verticalSpeed = Input.GetAxis("Vertical");

transform.position += transform.forward verticalSpeed moveSpeed * Time.deltaTime;

transform.position += transform.right * horizontalSpeed moveSpeed Time.deltaTime;

transform.position += transform.up DepthControl climbSpeed * Time.deltaTime;

transform.position -= transform.up bouancy Time.deltaTime;

}

And i have the other analogue stick controlled by the 'mouse look' standard script attached to the object. As well as the triggers on the back for climbing and decending.

It all looks fairly well so far, but im stuck with how to get the object to tilt when it slides side to side using my 'horizontalSpeed' axis.

i have tried adding

transform.Rotate(Vector3.right, Time.deltaTime);

to it, and other variations, but nothing seems to make it rotate.

Is there some easier way of doing this? - or have i just failed to understand something.

Could the mouse look be canceling out my rotation values?

Any advice would be appreciated, thanks!

  • Graeme.

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 Cyb3rManiak · Apr 26, 2011 at 09:08 AM

I think you're right, and in your case the mouse look script is canceling your rotation. To start I would try and disable the mouse look scripts and try and make the tilting work.

After that look in the mouse look script and see where it updates transform.rotation or transform.localRotation.

I have a MouseLook script here, but I'm not sure it's the original one. Anyway, there should be a line similar to

transform.localRotation = originalRotation * xQuaternion * yQuaternion

Each frame the local rotation is reset to the value set here, so if your script happens to run before the mouse look script - you won't see the tilt. Script run order is pretty random unless you make some steps to sync them.

Try and adding your tilt right after this line.

I would even edit this line. Maybe add a zQuaternion that will hold the tilt rotation. Just remember that in that case - you can't really use transform.Rotate since it's a method that rotates the object X degrees EACH FRAME. I would create the necessary quaternion just like the xQuaternion and the yQuaternion are created.

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 Graeme P · May 02, 2011 at 07:44 AM 0
Share

Thanks so much for the reply, i havent quite got it working yet, but with some tweaking itl be perfect.

Thanks again!

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

Face Direction Movement using CharacterController 1 Answer

How do I lock the Y rotation on a first person character controller 1 Answer

Maintain direction regardless of orientation (2) 1 Answer

Character Controller Rotation 4 Answers

Character Controller Movement - Different speeds on different axis 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