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 Panik.Studios · Aug 23, 2012 at 08:21 PM · inputcharactercontroller

How would I Trigger a Change in Inputs

I have 2 scripts attached to my Player.

Here:

(SSController)

 public var cont1 : int;
 private var motor : CharacterMotor;
 
 // Use this for initialization
 function Awake () {
     motor = GetComponent(CharacterMotor);
 }
 
 // Update is called once per frame
 
 function Update () {
     
     if (cont1 == 1){
     // Get the input vector from kayboard or analog stick
     var directionVector = new Vector3(Input.GetAxis("SSVertical"), 0, Input.GetAxis("SSHorizontal"));
     
     if (directionVector != Vector3.zero) {
         // Get the length of the directon vector and then normalize it
         // Dividing by the length is cheaper than normalizing when we already have the length anyway
         var directionLength = directionVector.magnitude;
         directionVector = directionVector / directionLength;
         
         // Make sure the length is no bigger than 1
         directionLength = Mathf.Min(1, directionLength);
         
         // Make the input vector more sensitive towards the extremes and less sensitive in the middle
         // This makes it easier to control slow speeds when using analog sticks
         directionLength = directionLength * directionLength;
         
         // Multiply the normalized direction vector by the modified length
         directionVector = directionVector * directionLength;
         }
     }
     // Apply the direction to the CharacterMotor
     motor.inputMoveDirection = transform.rotation * directionVector;
     motor.inputJump = Input.GetButton("Jump");
 }
 
 // Require a character controller to be attached to the same game object
 @script RequireComponent (CharacterMotor)
 @script AddComponentMenu ("Character/FPS Input Controller")
 

(SSControler2)

 public var cont1 : int;
 private var motor : CharacterMotor;
 
 // Use this for initialization
 function Awake () {
     motor = GetComponent(CharacterMotor);
 }
 
 // Update is called once per frame
 
 function Update () {
     
     if (cont1 == 2){
     // Get the input vector from kayboard or analog stick
     var directionVector = new Vector3(Input.GetAxis("SSHorizontal2"), 0, Input.GetAxis("SSVertical2"));
     
     if (directionVector != Vector3.zero) {
         // Get the length of the directon vector and then normalize it
         // Dividing by the length is cheaper than normalizing when we already have the length anyway
         var directionLength = directionVector.magnitude;
         directionVector = directionVector / directionLength;
         
         // Make sure the length is no bigger than 1
         directionLength = Mathf.Min(1, directionLength);
         
         // Make the input vector more sensitive towards the extremes and less sensitive in the middle
         // This makes it easier to control slow speeds when using analog sticks
         directionLength = directionLength * directionLength;
         
         // Multiply the normalized direction vector by the modified length
         directionVector = directionVector * directionLength;
         }
     }
     // Apply the direction to the CharacterMotor
     motor.inputMoveDirection = transform.rotation * directionVector;
     motor.inputJump = Input.GetButton("Jump");
 }
 
 // Require a character controller to be attached to the same game object
 @script RequireComponent (CharacterMotor)
 @script AddComponentMenu ("Character/FPS Input Controller")
 

and another script attached to a trigger that changes the int on each script accordingly.

The int changes on the scripts like it's supposed to.. But for some reason when Cont1 becomes 2

I loose all movement. . where my SSController2 script should begin it doesnt seem to want to work????

Whats going on?

Comment
Add comment · Show 1
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 Panik.Studios · Aug 23, 2012 at 08:48 PM 0
Share

If There is a better way to script an input change let me know please.. if this is a stupid way of changing controls that's fine just tell me what to do.. I'm a noob I wont get offended.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DaveA · Aug 23, 2012 at 09:19 PM

If I understand correctly, you want to switch between these 2 controller scripts, one active at a time, right?

First, using cont1 in both scripts does not make them both use the same variable. You would need one of them to be a static, and the other would not exist (other script would access the static var) or you would need to get the instance of that other component and get cont1 on it.

The way I've done this is have 3rd script with knows about the other 2 and just sets the 'enabled' flag on them accordingly

Comment
Add comment · Show 4 · 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 Panik.Studios · Aug 23, 2012 at 09:43 PM 0
Share

I do have a third script on the trigger... it looks like this

function OnTriggerEnter (other:Collider) { var cam = GameObject.FindGameObjectWithTag("$$anonymous$$ainCamera"); if(other.CompareTag("SSPlayer")) {

 //ASSINGS Interger Value To $$anonymous$$ainCamera Angle Script
 var ca1 = cam.GetComponent(camAngle);
 ca1.cameraAngle1 = 1;
 
 //ASSIGNS Interger Value To SSPlayer Control Script
 var ssp = GameObject.FindGameObjectWithTag("SSPlayer");
 var sp1 = ssp.GetComponent(SSController);
 sp1.cont1 = 2;
 var sp2 = ssp.GetComponent(SSController2);
 sp2.cont1 = 2;
 }

}

Like I said.. It changes the integer in both scripts correctly, but it's like it's not updating on the second script.. Im very confused.. It's completely possible Im overseeing something simple and not getting the point you're both making.

avatar image Panik.Studios · Aug 23, 2012 at 09:50 PM 0
Share

And yes you understood correctly.

avatar image Panik.Studios · Aug 23, 2012 at 10:15 PM 0
Share

I got it working thanks to ya.. Im not sure if this si what you were saying, but I changed the public variable for the second 1 to cont2 and made revisions in my trigger script as well.. If that's what you meant or not.. It made me realize it. thanks. I still think its strange that the way it was written b4 didnt work..

avatar image DaveA · Aug 23, 2012 at 10:24 PM 0
Share

Close enough! Glad you got it.

avatar image
0

Answer by BLarentis · Aug 23, 2012 at 09:17 PM

Hello, Well you don't need two scripts for that, one simple alteration that you can do is this:

(SSController)

 public var cont1 : int;
 private var motor : CharacterMotor;
 
 // Use this for initialization
 function Awake () {
     motor = GetComponent(CharacterMotor);
 }
 
 // Update is called once per frame
 
 function Update () {
 
     if (cont1 == 1){
     // Get the input vector from kayboard or analog stick
     var directionVector = new Vector3(Input.GetAxis("SSVertical"), 0, Input.GetAxis("SSHorizontal"));
 
     if (directionVector != Vector3.zero) {
        // Get the length of the directon vector and then normalize it
        // Dividing by the length is cheaper than normalizing when we already have the length anyway
        var directionLength = directionVector.magnitude;
        directionVector = directionVector / directionLength;
 
        // Make sure the length is no bigger than 1
        directionLength = Mathf.Min(1, directionLength);
 
        // Make the input vector more sensitive towards the extremes and less sensitive in the middle
        // This makes it easier to control slow speeds when using analog sticks
        directionLength = directionLength * directionLength;
 
        // Multiply the normalized direction vector by the modified length
        directionVector = directionVector * directionLength;
        }
     }else if(cont1 == 2){
     // Get the input vector from kayboard or analog stick
     var directionVector = new Vector3(Input.GetAxis("SSHorizontal2"), 0, Input.GetAxis("SSVertical2"));
 
     if (directionVector != Vector3.zero) {
        // Get the length of the directon vector and then normalize it
        // Dividing by the length is cheaper than normalizing when we already have the length anyway
        var directionLength = directionVector.magnitude;
        directionVector = directionVector / directionLength;
 
        // Make sure the length is no bigger than 1
        directionLength = Mathf.Min(1, directionLength);
 
        // Make the input vector more sensitive towards the extremes and less sensitive in the middle
        // This makes it easier to control slow speeds when using analog sticks
        directionLength = directionLength * directionLength;
 
        // Multiply the normalized direction vector by the modified length
        directionVector = directionVector * directionLength;
        }
 }
     // Apply the direction to the CharacterMotor
     motor.inputMoveDirection = transform.rotation * directionVector;
     motor.inputJump = Input.GetButton("Jump");
 }
 
 // Require a character controller to be attached to the same game object
 @script RequireComponent (CharacterMotor)
 @script AddComponentMenu ("Character/FPS Input Controller")


Well, see if that works for you. This way changing the variable at the first script will make the same script do your second script functions.

If this doesn't work try to see if your configurations on SSHorizontal2 and SSVertical2 axis are OK. If your intention is to invert the inputs when you enter the trigger, you could try and use this:

 var directionVector = new Vector3(Input.GetAxis("SSHorizontal"), 0, Input.GetAxis("SSVertical"));

instead of this:

  var directionVector = new Vector3(Input.GetAxis("SSHorizontal2"), 0, Input.GetAxis("SSVertical2"));

After your else if. If that isn't what you want, please ignore. Take care.

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 Panik.Studios · Aug 23, 2012 at 09:40 PM 0
Share

I tried doing something like this originally but I get the error that I already defined the variable earlier on in the script for both the direction Vector and The Direction Length... So I tried renai$$anonymous$$g the variable to dv and dl and it tells me I cannot do that... this is why i have two scripts.. I tried his script you posted but it wont run. for the same reasons.. Im confused about it..

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

9 People are following this question.

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

Related Questions

unity input system help 2 Answers

My player keeps launching into the sky 1 Answer

Don't jump continuously when button held down 0 Answers

Turning to face movement direction 0 Answers

Player inversed inputs 0 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