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 sgmongo · Nov 13, 2011 at 02:58 PM · charactercontrollerfly

Character Controller Fly

Hello Again!

So, I've got this character, its got the character controller script attached, as well as my own movement script(FPS style without the fps prefab). Now I'm trying to create a fly spell. Which obviously flips my character controller on its hindquarters.

Enter: my problem. The character controller apears to restrict Yaxis movement on the character. In order for the movement script to handle properly, I need the movement to be based on a y axis as well. Aim down, push forward, fly down. Simple see? I could be wrong but so far I've tried the following.

Specifically attaching a mouse look script with the Y section enabled.

Checking to see any of the objects y-rotation is constricted.

adding another object to the character to see if it rotates independantly of the CC. Which is doesn't.

I'll include my movement script just in case >.0

 //Speed Variable unstable above 25

 var speed = 6.0;
 
 var airspeed = 5.0;
 
 var jumpSpeed = 8.0;
 
 var gravity = 20.0;
 
 
 
 private var moveDirection = Vector3.zero;
 
 private var grounded : boolean = false;
 
 
 
 function FixedUpdate() {
 
 
 
     if (grounded) {
 
         // We are grounded, so recalculate movedirection directly from axes
 
         moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
 
         moveDirection = transform.TransformDirection(moveDirection);
 
         moveDirection *= speed;            
 
             if (Input.GetButton ("Jump")) {
 
             moveDirection.y = jumpSpeed;
 
             }
 
         }
 
         else {
 
         
 
         //Preserving fall value
 
         var fall = moveDirection.y;
 
         
 
         
 
         var NewmoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
 
         NewmoveDirection = transform.TransformDirection(NewmoveDirection);
 
         moveDirection = moveDirection + ((NewmoveDirection * airspeed) * Time.deltaTime);
 
         
 
         
 
         
 
         //Replacing Y movement value to original fall
 
         moveDirection.y = fall;
 
         }
 
 
 
     // Apply gravity
 
     moveDirection.y -= gravity * Time.deltaTime;
 
     
 
     // restrict to speed and Move the controller
 
     moveDirection.x = Mathf.Clamp(moveDirection.x, -speed, speed);
 
     moveDirection.y = Mathf.Clamp(moveDirection.y, -speed, speed);
 
     moveDirection.z = Mathf.Clamp(moveDirection.z, -speed, speed);
 
     var controller : CharacterController = GetComponent(CharacterController);
 
     var flags = controller.Move(moveDirection * Time.deltaTime);
 
     grounded = (flags & CollisionFlags.CollidedBelow) != 0;
 
     }
     
     
     
     @script RequireComponent(CharacterController)


Now that that's out of the way. Specifically my questions are.

Does the character controller stop y axis rotation?

If so, is there a handle to prevent this?

If not can you see a way to fix this?

Assuming its my programming, should I create a entirely seprate code handling the instance of gravity = 0 and onground.false?

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
0

Answer by sgmongo · Nov 14, 2011 at 09:19 PM

After extensive debugging I determined that the Y axis rotation was not prevented like I originally thought.

The issue actually lies in the mouse rotation scripts... Mouse look I believe most people call it. Apparently there is a reason they have you split the mouseX and mousey portions onto separate objects.

Somehow they interact and completely screw it up when you place both of them on a single object. I'll now be hunting for a X and Y Mouse look script to see if it solves the issue. (Note: the reason I'm not writing my own on this one is because I still don't understand quaternions well enough to tinker properly.)

In case anyone is following this thread I'll keeo you posted on the results.

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 sgmongo · Nov 15, 2011 at 02:01 AM 0
Share

Turns out there is a standard script included in unity for X and Y mouse rotation. After applying this script its been pretty easy to adapt the movement script I created to function differently in a zero gravity environment.

Once I expand upon the functionality of the included rotation script such that I can unlock the mouse and freeze the rotation input it will be completely useable for my fly spell.

I know its a feux pas to answer your own question which is why I won't be checkmarking it. But in case anyone was following along with my same issues. You should be able to follow my breadcrumbs. :D

avatar image AntFitch · Oct 12, 2012 at 03:59 PM 0
Share

This has been very helpful. Thanks, sgmongo!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Constant Force applied to player without rigidbody on button press 1 Answer

How to Set Gravity to a specific Object? 3 Answers

OnControllerColliderHit -> GetComponent on collided object not working 1 Answer

help with firing projectile, character controller + child object 1 Answer

Detect when CharacterController is not colliding? (SOLVED) 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