• 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 LaurensiusTony · Nov 27, 2013 at 07:29 AM · camera rotateface model

3rd person mobile control

Hi, i'm using player relative control from assets to move my character for my mobile game and i trying to make use just one joystick(left one) to control my movement and my camera rotation but when i move my joystick 'X' axis which suppose to make my character move left or right but my model face is not facing that direction it just like i moving like a crab(face forward but body moving left and right) anyone can help?here is code from player relative control that i already tweaked

 function Update()
 {
     var movement = thisTransform.TransformDirection( Vector3( moveJoystick.position.x, 0, moveJoystick.position.y ) );
 
     // We only want horizontal movement
     movement.y = 0;
     movement.Normalize();
 
     var cameraTarget = Vector3.zero;
 
     // Apply movement from move joystick
     var absJoyPos = Vector2( Mathf.Abs( moveJoystick.position.x ), Mathf.Abs( moveJoystick.position.y ) );    
     if ( absJoyPos.y > absJoyPos.x )
     {
         if ( moveJoystick.position.y > 0 ){
             movement *= forwardSpeed * absJoyPos.y;
             
         }
         else
         {
             movement *= backwardSpeed * absJoyPos.y;
             cameraTarget.z = moveJoystick.position.y * 0.75;
         }
     }
     else
     {
         movement *= sidestepSpeed * absJoyPos.x;
         
         // Let's move the camera a bit, so the character isn't stuck under our thumb
         cameraTarget.x = -moveJoystick.position.x * 0.5;
     }
     
     // Check for jump
     if ( character.isGrounded )
     {
         //if ( rotateJoystick.tapCount == 2 )
         //{
             // Apply the current movement to launch velocity        
         //    velocity = character.velocity;
         //    velocity.y = jumpSpeed;            
         //}
     }
     else
     {            
         // Apply gravity to our velocity to diminish it over time
         velocity.y += Physics.gravity.y * Time.deltaTime;
         
         // Move the camera back from the character when we jump
         cameraTarget.z = -jumpSpeed * 0.25;
         
         // Adjust additional movement while in-air
         movement.x *= inAirMultiplier;
         movement.z *= inAirMultiplier;
     }
         
     movement += velocity;    
     movement += Physics.gravity;
     movement *= Time.deltaTime;
     
     // Actually move the character    
     character.Move( movement );
     
     if ( character.isGrounded )
         // Remove any persistent velocity after landing    
         velocity = Vector3.zero;
     
     // Seek camera towards target position
     var pos = cameraPivot.localPosition;
     pos.x = Mathf.SmoothDamp( pos.x, cameraTarget.x, cameraVelocity.x, 0.3 );
     pos.z = Mathf.SmoothDamp( pos.z, cameraTarget.z, cameraVelocity.z, 0.5 );
     cameraPivot.localPosition = pos;
 
     // Apply rotation from rotation joystick
     if ( character.isGrounded )
     {
         var camRotation = moveJoystick.position;
         camRotation.x *= rotationSpeed.x;
         //camRotation.y *= rotationSpeed.y;
         camRotation *= Time.deltaTime;
         
         // Rotate the character around world-y using x-axis of joystick
         thisTransform.Rotate( 0, camRotation.x, 0, Space.World );
         
         // Rotate only the camera with y-axis input
         //cameraPivot.Rotate( camRotation.y, 0, 0 );
     }
 
 }
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
Best Answer

Answer by LaurensiusTony · Nov 27, 2013 at 03:53 PM

fixed by using camera relative control

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Rotation(Y) and Acceleration Camera 0 Answers

Tank stabilization 1 Answer

Why does the default Third Person Controller cause my character to spin in place? 4 Answers

Unity 2D... getting accurate X and Y values of camera when rotating it. 1 Answer

Adjust camera orientation through code 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges