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 d-pav · Apr 26, 2014 at 08:31 PM · vector3charactercontrollerdirectionvectorvector3.angle

Can't change vector direction

Hello, I'm trying to develop a mobile controller (with two touchpads) that uses Character Motor script. I'm almost done. The only thing is that when I'm applying that vector to the Character Motor script, I need to write the rotation like this: motor.inputMoveDirection = transform.rotation * movement; But it's not working. Forward is always forward only in one direction, regardless of which way my camera and the character are pointing. I've tried creating another variable for the object, rotate it according to the camera, etc. Nothing works.

Here is the full script, which is a combined version of FPSInputController (from Standard Assets) and FirstPersonControl (from Standard Assets (mobile)). Disregard all the variables that are not used, I'll delete them later.

 #pragma strict
 
 @script RequireComponent( CharacterController )
 
 // This script must be attached to a GameObject that has a CharacterController
 var moveTouchPad : Joystick;
 var rotateTouchPad : Joystick;                        // If unassigned, tilt is used
 
 var cameraPivot : Transform;                        // The transform used for camera rotation
 
 var forwardSpeed : float = 4;
 var backwardSpeed : float = 1;
 var sidestepSpeed : float = 1;
 var jumpSpeed : float = 8;
 var inAirMultiplier : float = 0.25;                    // Limiter for ground speed while jumping
 var rotationSpeed : Vector2 = Vector2( 50, 25 );    // Camera rotation speed for each axis
 var tiltPositiveYAxis = 0.6;
 var tiltNegativeYAxis = 0.4;
 var tiltXAxisMinimum = 0.1;
 
 private var thisTransform : Transform;
 private var character : CharacterController;
 private var cameraVelocity : Vector3;
 private var velocity : Vector3;                        // Used for continuing momentum while in air
 private var canJump = true;
 private var motor : CharacterMotor;
 
 function Start()
 {
     motor = GetComponent(CharacterMotor);
 
     // Cache component lookup at startup instead of doing this every frame        
     thisTransform = GetComponent( Transform );
     character = GetComponent( CharacterController );    
 }
 
 function Update()
 {
     var movement = thisTransform.TransformDirection( Vector3( moveTouchPad.position.x, 0, moveTouchPad.position.y ) );
 
     // We only want horizontal movement
     //movement.y = 0;
     //movement.Normalize();
 
     motor.inputMoveDirection = transform.rotation * movement;
 
     // Apply rotation from rotation joystick
     if ( character.isGrounded )
     {
         var camRotation = Vector2.zero;
         
         if ( rotateTouchPad )
             camRotation = rotateTouchPad.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 );
     }
 }

So, how do I make it that vector change its rotation based on the player's or camera's rotation? So that forward is wherever character is pointing? Thank you all in advance!

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

0 Replies

· Add your reply
  • Sort: 

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

20 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 avatar image avatar image avatar image avatar image

Related Questions

C# Raycast from Object direction (z-axis) + another Vector3 1 Answer

Vector direction after collision 1 Answer

Fire Knockback 3 Answers

Rotating a direction Vector3 by Quaternion 2 Answers

Vector based on the rotation of the main camera 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