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 Juan105ify · Jul 21, 2014 at 05:31 PM · inputmanager

Input Manager

Hey guys I'm been trying to move a character using the input manager. I was able to have the character move forward, but he doesn't move backwards though. I have my S key as the negative button and I was sure it would turn my positive value into a negative value. Here is my code on how i'm moving my character

 using UnityEngine;
 using System.Collections;
 
 // Require these components when using this script
 [RequireComponent(typeof(Animator))]
 [RequireComponent(typeof(CapsuleCollider))]
 [RequireComponent(typeof(Rigidbody))]
 public class Wolf_AnimationInput : MonoBehaviour {
 
     public float animSpeed = 1.5f;                // a public setting for overall animator animation speed
     public float lookSmoother = 3f;             // a smoothing setting for camera motion
     public float moveSpeed = 0.5f;
     public float rotateSpeed = 180;
 
     private Animator anim;
     private AnimatorStateInfo currentBaseState;// a reference to the animator on the character
     private CapsuleCollider col;        // a reference to the capsule collider of the character
     private CharacterController controller;
     private Transform _mytransform;
 
     static int idleState = Animator.StringToHash("Base Layer.Idle");
     static int runState = Animator.StringToHash("Base Layer Run");
     static int attackState = Animator.StringToHash("Base Layer.Attacks");
 
     // Use this for initialization
     void Start () {
 
         _mytransform = transform;
         anim = GetComponent<Animator>();
         col = GetComponent<CapsuleCollider>();
     
     }
     
     // Update is called once per frame
     void Update () {
 
         float v = Input.GetAxis("Vertical");                // setup v variables as our vertical input axis
         anim.SetFloat("Speed", v);
         anim.speed = animSpeed;
         currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
 
         if (currentBaseState.nameHash == idleState)
         {
             if (Input.GetButtonDown("Attack"))
             {
                 anim.SetBool("Atk", true);
             }
             else
             {
                 anim.SetBool("Atk", false);
             }
         }
 
         if(Input.GetButton("Vertical"))
         {  
             _mytransform.Translate(new Vector3(0.0f, 0.0f, 0.0f) * Time.deltaTime);  
         }
 
         if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0)
         {
             _mytransform.Rotate(0, Input.GetAxis("Horizontal") * Time.deltaTime * rotateSpeed, 0);
         }
 
        
     }
 }
Comment
Add comment · Show 3
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 tanoshimi · Jul 21, 2014 at 07:02 PM 0
Share

if(Input.GetButton("Vertical")) { _mytransform.Translate(new Vector3(0.0f, 0.0f, 0.0f) * Time.deltaTime); }

What are you trying to do with these lines?

avatar image Juan105ify · Jul 21, 2014 at 07:27 PM 0
Share

oh no it's alright i fixed the problem

avatar image Loius · Jul 21, 2014 at 08:01 PM 0
Share

Please delete or answer the question (and accept the answer using the checkmark) if you don't need any help.

1 Reply

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

Answer by Juan105ify · Jul 21, 2014 at 07:55 PM

Hey guys i Fixed the problem. The problem was i was setting the Value of the Vertical to 2. So it would always be a positive number. So i looked up and saw that using the GetAxis would fix the problem

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Players on one Computer/Console 5 Answers

Using InputManager problems? 1 Answer

Custom Input manager problem 0 Answers

problem while configurating controller 0 Answers

Allow CrossPlatformInputManager to use a Custom VirtualInput extended Class [Unity5] 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