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 cooledcannon · Oct 08, 2013 at 01:09 AM · movement script

My movement keys are opposite to actual movement?

For background, im doing the stealth tutorial, player movement. Ive followed the instructions, but when I came to test it, the movements are backwards. (eg W/up moves down, A/left moves right etc) Weirdly, when I sneak, the movement is the right way round.

Any ideas where I have gone wrong? If I cannot find what went wrong, should I just try to add something that inverts the keys?

Edited for clarity. So here are my issues:

My code seems to be good

My input manager settings seem to be good

My keyboard seems to be good

I face the correct direction, but I move backwards.

During Sneak, I face the correct direction and move forwards.

If I invert using the input manager I face the wrong direction and move correctly, and in sneak I face the wrong direction and move backwards.(basically doing what invert should do)

The web player seems to be working fine, and after I go through the build settings, things work well with no problems.

Both my version and the done version have this problem, but another project(roll a ball) does not.

Comment
Add comment · Show 8
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 meat5000 ♦ · Oct 08, 2013 at 01:11 AM 0
Share

Your model sounds like it is aligned in the 3D software 180 degrees to Unity world axes. Is there rotation in the transform?

avatar image cooledcannon meat5000 ♦ · Oct 08, 2013 at 01:31 AM 0
Share

No, there is no rotation for the player character.

avatar image meat5000 ♦ · Oct 08, 2013 at 02:14 AM 0
Share

Did you simply put your $$anonymous$$uses in the wrong place? -x ins$$anonymous$$d of x for example in your movement scripts?

avatar image cooledcannon · Oct 08, 2013 at 02:45 AM 0
Share

I dont have any $$anonymous$$uses in my scripts afaik

avatar image cooledcannon · Oct 08, 2013 at 02:47 AM 0
Share

here is my code:

using UnityEngine; using System.Collections;

public class Player$$anonymous$$ovement : $$anonymous$$onoBehaviour { public AudioClip shoutingClip; public float turnSmoothing = 15f; public float speedDampTime = 0.1f;

 private Animator anim;
 private HashIDs hash;
 
 void Awake()
 {
     anim = GetComponent<Animator>();
     hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<HashIDs>();
     anim.SetLayerWeight(1, 1f);
 }    
 
 void FixedUpdate()
 {
     float h = Input.GetAxis("Horizontal");
     float v = Input.GetAxis("Vertical");
     bool sneak = Input.GetButton("Sneak");
     
     $$anonymous$$ovement$$anonymous$$anagement(h, v, sneak);
 }
 
 void Update()
 {
     bool shout = Input.GetButtonDown("Attract");
     anim.SetBool(hash.shoutingBool, shout);
     Audio$$anonymous$$anagement(shout);
 }    
 
 void $$anonymous$$ovement$$anonymous$$anagement(float horizontal, float vertical, bool sneaking)
 {
     anim.SetBool(hash.sneakingBool, sneaking);
     
     if(horizontal != 0f || vertical != 0f)
     {
         Rotating(horizontal, vertical);
         anim.SetFloat(hash.speedFloat, 5.5f, speedDampTime, Time.deltaTime);            
     }    
     else
     {
         anim.SetFloat (hash.speedFloat, 0f);
     }    
 }    
 
 void Rotating(float horizontal, float vertical)
 {
     Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
     Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
     Quaternion newRotation = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * Time.deltaTime);
     rigidbody.$$anonymous$$oveRotation(newRotation);
 }
 
 void Audio$$anonymous$$anagement(bool shout)
 {
     if(anim.GetCurrentAnimatorStateInfo(0).nameHash == hash.locomotionState)
     {
         if(!audio.isPlaying)
         {
             audio.Play ();
         }    
     }
     else
     {
         audio.Stop();
     }
     
     if(shout)
     {
         AudioSource.PlayClipAtPoint(shoutingClip, transform.position);
     }
 }

}

avatar image TrickyHandz · Oct 08, 2013 at 03:52 AM 0
Share

Your code looks sound. In fact aside from some very $$anonymous$$or formatting differences it is exactly what is in the finished scripts for the S$$anonymous$$lth project. Out of curiosity, are the key in your Input $$anonymous$$anager for the Horizontal and Vertical axis reversed?

Show more comments

8 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DanTup · Jan 01, 2014 at 05:15 PM

Have you just got your camera positioned on the wrong side of the character, so they directions are inverted?

Comment
Add comment · Show 2 · 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 cooledcannon · Jan 02, 2014 at 02:39 AM 0
Share

Sometimes, on occasion the camera screws up like that. But the two are unrelated in my testing, it always has the wrong direction from the start.

avatar image MikaHentrqww · Feb 14, 2019 at 05:44 AM 0
Share

THAN$$anonymous$$ YOU SO $$anonymous$$UCH FOR THIS CO$$anonymous$$$$anonymous$$ENT!!!

avatar image
1

Answer by ben_friedman · May 30, 2014 at 07:26 PM

If you click on the "game" screen during testing, then your keys should work correctly. If you click on the "scene" screen to readjust the camera while you are testing the game, your keys will get reversed. Can anyone confirm that this is the symptom we are all having? If so, the quick solution is to click on the "game" screen while you're testing.

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

Answer by DyrdaOrg · Oct 08, 2013 at 07:47 AM

Go here:

http://unity3d.com/learn/tutorials/projects/stealth/player-movement

And try to copy-paste entire code... If it won't help - then problem is with Unity. If that helps - then the code has fault (although I have almost the same).

You can also go to:

YourProjectDirectory/Done/DoneScenes and fire up DoneStealth.unity

If problem occurs even then... well... maybe some kind of beverage was spilled on your keyboard or cat was sitting there? ;)

Comment
Add comment · Show 11 · 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 cooledcannon · Oct 08, 2013 at 08:19 AM 0
Share

Yeah, the code isnt the problem. Also, when I fired up the done scene, i had the same problem. The character is facing correctly, just moving in the opposite direction. During sneak, it moves in the correct direction.

avatar image DyrdaOrg · Oct 08, 2013 at 08:30 AM 0
Share

So, just to be sure, not only your scene

YourProjectDirectory/Scenes/S$$anonymous$$lth.unity

but also

YourProjectDirectory/Done/DoneScenes/DoneS$$anonymous$$lth.unity

is working incorrectly?

avatar image cooledcannon · Oct 08, 2013 at 08:46 AM 0
Share

Yes. Both are working incorrectly. They also have the same problem, from what I can tell.

avatar image DyrdaOrg · Oct 08, 2013 at 08:53 AM 0
Share

I'm sorry, but that means that the problem is with your/drivers, keyboard, laptop, etc.

Try to connect different keyboards - maybe this help cause that project was done by me in July and works, and recently was downloaded by my colagues and works perfectly in movement matter.

avatar image cooledcannon · Oct 08, 2013 at 08:55 AM 0
Share

Does this mean the problem is isolated on my computer, and the project itself will work on other computers?

Show more comments
avatar image
0

Answer by DannyBurbol · Oct 21, 2013 at 05:38 AM

I'm also walking through the Stealth tutorials and I'm getting exactly the same issue cooledcannon started this post with.

The interesting thing is, pressing the stealth key makes the character walk forward correctly and releasing it has the character moving in reverse again. (just as cooledcannon described)

this sounds like it's animation specific or state specific, however, when I go to the Animator tab and click on the transitions from Idle to Locomotion or from Idle to Sneak, the Preview clearly shows the character walking forward and stepping away from the origin of the Preview window.

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 DannyBurbol · Oct 21, 2013 at 05:40 AM 0
Share

small update with progress: I went into the Animator for the player and double-clicked the Locomotion node on the Base Layer.

This brings me to the Blend Tree with Walk and Run based on speed.

If I change the animations in the Blend Tree from Walk and Run, to Walk and Walk, the character walks in the correct direction (and never plays the run anim)

If I change the animations in the Blend Tree to Run and Run, the character runs in the reverse direction that they are facing (which is the issue what started this thread).

It seems to me that the Run anim has an issue. However I'm not sure how to identify or correct it.

I tried to compare humanoid_runForward_faceForward with humanoid_sneak and humanoid_walkForward_faceForward, but didn't see any obvious difference.

I also tried to experiment with check/uncheck of some of the params in the humanoid_runForward_faceForward inspector window, but it didn't seem to make any difference.

for now, I'm continuing the tutorial with just the walk anim.

avatar image cooledcannon · Oct 21, 2013 at 07:33 AM 0
Share

Hey man, thanks for the help, its appreciated.

I decided to change the Run animation to another Walk animation. Its a bit slow, but things are working great. Do you know how to increase the walking speed?

Also, the problem is really weird. Sometimes I would always go backwards(maybe a very short tap makes it go forwards), sometimes always forwards, sometimes mix of forwards and backwards(which was incredibly annoying)

avatar image DannyBurbol · Oct 22, 2013 at 05:12 AM 0
Share

Okay, I thought I found a fix.... but it turns out it only works when pressing the play button in Unity. when I built and ran the final game... the character runs facing backwards.

for the record, here's what I tried....

  1. in Hierarchy Tab: click on char_ethan.

  2. in Inspector Tab: double-click PlayerAnimator

  3. in the Animator Tab: in the "Base Layer", double-click Locomotion node.

  4. in the Animator Tab: in the "Base Layer > Locomotion", click the other Locomotion node (the blend tree node)

  5. in the inspector: originally this had "Walk" and "Run" entries (and in my previous post, I made a note about trying "Walk" and "Walk" vs "Run" and "Run")

  6. restore this to have the entries "Walk" and "Run"

  7. note, there are 4 columns in that little table: "$$anonymous$$otion", "Threshold", a clock, and a little man split in half.

  8. I hovered over the clock icon and it said: "Changes animation speed"

  9. I changed this column to read: 1 for Walk, and -1 for Run.

I repeat, this worked when testing in Unity... but once I did a Build and Run, the character was facing backward. :(

avatar image DannyBurbol · Oct 22, 2013 at 05:29 AM 0
Share

Wow... so that last failed experiment led me full circle.

I restored the Walk and Run to both use 1 and 1 for "Changes animation speed" column.

in Unity, when I use the play button, the character runs backwards in the preview window.

but if I do a "File" > "Build & Run", the character works correctly and runs forward.

So the issue is in the preview window... but not in the final game.

I'm using Unity 4, version 4.2.2f1

avatar image
0

Answer by yogee · Oct 22, 2013 at 05:38 AM

use -h,-v

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
  • 1
  • 2
  • ›

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

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

Related Questions

Slow vehicle to stop 1 Answer

How to disable A, S, and D keys for third person player movement 1 Answer

My player goes straight through my colider 3 Answers

My character moves when i dont want to 0 Answers

Movement based on 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