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 /
This question was closed Dec 09, 2013 at 12:31 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by fullme7al · Dec 07, 2013 at 02:23 AM · charactercontrollercontrollerroll

Character rolls consistently in all directions, but right.

First of all thank you for reading this. I modified the Penelope controls to move the character and have him face either right or left with one joystick. I have the character moving at another speed with the press of a button which will be a roll animation. When I press the roll button it works fine, except when the character is facing right and moving right. When I try to roll to the right works probably 25 percent of the time. I have no idea where the problem lies and it's getting a pit frustrating. Thank you for all and any help in advance.

 using UnityEngine;
 using System.Collections;
 
 
 [RequireComponent(typeof(CharacterController))]
 public class BaseControlsCC22 : MonoBehaviour {
     
     
     
     public MPJoystick moveJoystick;
     public float speed =                     6.0f;
     public Transform cameraTransform;
     public float rollSpeed = 10.0f;
     
 
     public float gravity =                     10.0f;
     
     public GUITexture rollButton;
     
     
 
     private Transform myTransform; //our characters transform
     private CharacterController character; //getting our characters controller
     
     // Use this for initialization
     public virtual void Awake(){
         myTransform = transform;
         character = GetComponent<CharacterController>();
     }
     
     // Update is called once per frame
     void Update () {
         movement (); //how we move
         FaceMovementDirection ();//this is us facing a new direction
     }
     public virtual void movement(){
         
         Vector3 moveDirection = cameraTransform.TransformDirection(new Vector3( moveJoystick.position.x, 0.0f, moveJoystick.position.y ) );
         // We only want the camera-space horizontal direction
         moveDirection.y = 0.0f;
         moveDirection.Normalize(); // Adjust magnitude after ignoring vertical movement
         
         // Let's use the largest component of the joystick position for the speed.
         Vector2  absJoyPos = new Vector2( Mathf.Abs( moveJoystick.position.x ), Mathf.Abs( moveJoystick.position.y ) );
         moveDirection *= speed * ( ( absJoyPos.x > absJoyPos.y ) ? absJoyPos.x : absJoyPos.y );
         
         // how to roll
         foreach(Touch touch in Input.touches)
         {
             if ( character.isGrounded )
             {
                 if ( touch.phase == TouchPhase.Began && rollButton.HitTest(touch.position) )
                 {
                     // Apply the current movement to roll
                     moveDirection *= rollspeed * ( ( absJoyPos.x > absJoyPos.y ) ? absJoyPos.x : absJoyPos.y );
 
                     
                 }
             }
 
         }
         moveDirection.y -= gravity * Time.deltaTime;
         // Actually move the character
         character.Move( moveDirection * Time.deltaTime );
     }
     
     public virtual void FaceMovementDirection()
     {    
         Vector3 horizontalGravity = character.velocity;
         horizontalGravity.y = 0; // Ignore vertical movement
         horizontalGravity.z = 0; // ignore looking on z axis
         // If moving significantly in a new direction, point that character in that direction
         if ( horizontalGravity.magnitude > 0.1 )
             myTransform.forward = horizontalGravity.normalized;
     }
     
 }
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

  • Sort: 
avatar image
0
Best Answer

Answer by fullme7al · Dec 09, 2013 at 12:31 AM

I have a knack for solving my own problems. I fixed it. The floor was slanted so the character wasn't grounded.

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

Follow this Question

Answers Answers and Comments

16 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

controller.SimpleMove slower when Character go Backward 1 Answer

Follow script problem 1 Answer

CharacterController unexpectedly moving up 0 Answers

My unfortunate swimmer endlessly sinks. Help! 3 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