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 Desination-X · Aug 01, 2014 at 10:13 PM · movementcharacterfly

When I look down and move forward, I fly upwards

I have my own super basic movement script, and everytime I walk forward while looking down, my character goes upwards at an angle. It goes up and forward, if that makes sense.

I did some research and found people who had similar problems, but no one with the problem I am having.

Any idea why this is happening? Oh, and on a side note, even though my walk speed is 0.1, my character is still relatively fast.

Here is my script:

 using UnityEngine;
 using System.Collections;
 
 public class CharacterMovement : MonoBehaviour {
     
     public float walkSpeed = 0.1F;
     public float runSpeed = 1.0F;
     public float jumpSpeed = 5.0F; 
     public float gravity = 20.0F;
     public float jumpTimer = 1.5F;
 
     public bool sprinting;
 
     CharacterController controller;
 
     private Vector3 moveDirection = Vector3.zero;
 
     private bool canJump = true;
 
     PlayerInventory playerInventory;
 
     DebugConsole debugConsole;
 
     void Start () {
         controller = GetComponent<CharacterController>();
         playerInventory = GetComponent<PlayerInventory>();
         debugConsole = GameObject.Find ("_SCRIPTS").GetComponent<DebugConsole>();
     }
 
     // Update is called once per frame
     void Update () {
         if(controller.isGrounded && !PauseMenu.paused && !debugConsole.commandLine && !playerInventory.inInventory){
             moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
 
             if(Input.GetKeyDown(KeyCode.LeftShift) && Player.Stamina > 0)
                 sprinting = true;
             if(Input.GetKeyUp(KeyCode.LeftShift))
                 sprinting = false;
 
             if(sprinting)
                 moveDirection *= runSpeed;
             else
                 moveDirection *= walkSpeed;
 
             if (Input.GetButton("Jump") && canJump && Player.Stamina > 10){
                 canJump = false;
                 StartCoroutine(jumpDelay());
                 moveDirection.y = jumpSpeed;
                 Player.setStamina(-5);
             }
         }
 
         moveDirection.y -= gravity * Time.deltaTime;
 
         controller.Move(moveDirection);
     }
 
     IEnumerator jumpDelay () {
         yield return new WaitForSeconds(jumpTimer);
         canJump = true;
     }
 
 }
 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Edit this code? 0 Answers

Space Invaders movement? 1 Answer

BCE0044: Expecting : Found = Error! 2 Answers

Controlling AI Movement 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