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 Chaos Warp · Mar 06, 2013 at 06:21 AM · movementspeedtutorialburgzergarcade

How come my character is moving so fast?

I am following the tutorials at Burgzergarcade.com and I just set up the movement. The script itself works but it seems to make me move incredibly fast compared to the tutorial video. Sorry if the code is formatted weird. It might be super fast because the tutorial was not using Unity 4.

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof(CharacterController))]
 public class AdvancedMovement : MonoBehaviour {
     public float walkSpeed = 2;                    //the speed our character walks at
     public float runMultiplier = 12;            //how fast the player runs compared to the walk speed
     public float strafeSpeed = 2.5f;            //the speed our character strafes at
     public float rotateSpeed = 250;                //the speed our character turns at
     public float gravity = 20;                    //the setting for gravity
     public float airTime = 0;                    //how long have we been in the air since the last time we touched the ground
     public float fallTime = 0.5f;                //the length of time we have to be falling before the system knows its a fall
     public float jumpHeight = 0.5f;                //the height we move when we are jumping
     public float jumpTime = 1.5f;                
     
     
     private CollisionFlags _collisionFlags;        //the collisionFlags we have from last frame
     private Vector3 _moveDirection;                //this is the direction our character is moving
     private Transform _myTransform;                //our cached transform
     private CharacterController _controller;    //our cached CharacterController
 
     
     //Called before the script starts
     public void Awake(){
         _myTransform = transform;
         _controller = GetComponent<CharacterController>();
     }
     
     // Use this for initialization
     void Start () {
         _moveDirection = Vector3.zero;
         
         animation.Stop ();
         
         animation.wrapMode = WrapMode.Loop;
         
         animation["GoodWalk"].layer = 1;                    //this is for the jump animation. I dont have a jump animation. Replace GoodWalk with Jump
         animation["GoodWalk"].wrapMode = WrapMode.Once;        //this is for the jump animation. I dont have a jump animation. Replace Goodwalk with Jump
         
         animation.Play("GoodIdle");
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.GetButton("Horizontal")) {
             _myTransform.Rotate(0, Input.GetAxis("Horizontal") * Time.deltaTime * rotateSpeed, 0);     
         }
         
         
         if(_controller.isGrounded){
             airTime = 0;
         
             _moveDirection = new Vector3(0, 0, Input.GetAxis ("Vertical"));
             _moveDirection = _myTransform.TransformDirection(_moveDirection).normalized;
             _moveDirection *= walkSpeed;
             
             if(Input.GetButton ("Vertical")) {
                 if(Input.GetButton("Run")) {
                     _moveDirection *= runMultiplier;
                     Run ();
                 }
                 else {
                     Walk ();
                 }
             }
             else {
                 Idle ();
             }
             
             if(Input.GetButton("Jump")) {
                 if(airTime < jumpTime) {
                     _moveDirection.y += jumpHeight;
                     Jump();
                 }
             }
                 
         }
         else{
             
             if((_collisionFlags & CollisionFlags.CollidedBelow) == 0){
                 airTime += Time.deltaTime;
                 
                 if(airTime > fallTime) {
                     Fall();
                 }
             }
         }
         
         _moveDirection.y -= gravity * Time.deltaTime;
         
         _collisionFlags = _controller.Move(_moveDirection);
     }
     
     public void Idle() {
         animation.CrossFade("GoodIdle");
     }
     
     public void Walk() {
         animation.CrossFade("GoodWalk");
     }
     
     public void Run() {                            //Need a running animation
         animation["GoodWalk"].speed = 1.5f;        //Need a running animation
         animation.CrossFade("GoodWalk");        //Need a running animation
     }
     
     public void Jump() {                        //Need a jump animaiton
         animation.CrossFade("AxeSlash");        //Need a jump animation
     }
     
     public void Strafe() {                        //Need a strafe animation
         animation.CrossFade("NormIdle");        //Need a strafe animation
     }
     
     public void Fall() {                        //Need a falling animation
         animation.CrossFade("CombatStance");    //Need a falling animation
     }
 }
 
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

2 Replies

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

Answer by kramcomposer · Mar 06, 2013 at 06:51 AM

try putting this in:

_moveDirection = runMultiplier Time.deltaTime;

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
0

Answer by Chaos Warp · Mar 06, 2013 at 07:33 AM

Nevermind! lol, I solved it, I added it to the end of

 _moveDirection = _myTransform.TransformDirection(_moveDirection).normalized * Time.deltaTime;

Thanks for the advice, totally forgot about Time.deltaTime.

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

11 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

Related Questions

Character moves slower after build 3 Answers

Can't change the speed of a character. 2 Answers

My Character is moving fine horizontally and vertically, but moves way too fast diagonally 2 Answers

How to move object along Spline at constant speed? 0 Answers

Is mixing movement types a bad thing to do? (Force and Translate) 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