Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Waraikou · Mar 30, 2018 at 11:48 AM · charactercontrollercontrollersideways

I can't move left or right with my moving script

Hello guys ! First post here. I'm not a programer at all but for my video game art diploma i need to make some scripts in order to get a playable game. I'm working on a third person game and I had a question about this character controller script I copied from this Youtube Tutorial : Melee combat with Unity 5

My problem is, i can perfectly move on the Z axis with a decent speed, the script lauches the run animation of my character and i can move left or right by moving the camera (cinemachine brain targetting my character). But the problem appears if i want to move right or left (so when i want to use the X axis i presume) by pressing Right and Left Arrows. My character is moving, staying idle but moving but this is so slow ! I can increase the float speed in my public function and get a decent side step speed, but the Z axis is increased too and my character is too fast if i press Up or Down arrow. I would like to get the same speed for Forward/Backward AND side movements. Idid a quick video to show you the problem : Character Controller Script Issue

I think there is a solution somewhere in the script to fix that, but i'm too noob at C# to find where it is. I'll be really happy if you, skill full programers could take look at it and see where my problem is. Thank you in advance !

Here is the script (i added some lines to it ) :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class characterController1 : MonoBehaviour {
 
     static Animator anim;
     public float speed = 10.0F;
     public Slider healthbar;
     public ParticleSystem particles;
     public float fireRate = 0.5F;
     private float nextFire = 0.0F;
     // Use this for initialization
     void Start () 
     {
         anim = GetComponent<Animator> ();
         //Cursor.lockState = CursorLockMode.Locked;
 
     }
     
     // Update is called once per frame
     void Update () 
     {
         if (healthbar.value <= 0) return;
 //
         var x = Input.GetAxis("Horizontal") * Time.deltaTime * 100.0f;
         var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
         var y = Input.GetAxis("Horizontal") * Time.deltaTime * 3.0f;
 //
         transform.Rotate(0, x, 0);
         transform.Translate(0, 0, z);
 
         float translation = Input.GetAxis ("Vertical") * speed;
         float straffe = Input.GetAxis ("Horizontal") * speed;
         straffe *= Time.deltaTime;
 
         transform.Translate (straffe, 0, translation);
 
         //if (Input.GetButtonDown ("right"))
             //transform.Translate(2, 0, z);
 
         if (Input.GetButtonDown ("Fire1") && Time.time > nextFire)  
         {
             nextFire = Time.time + fireRate;
             particles.Play();
             anim.SetBool ("isAttacking", true);
         } 
         else
             anim.SetBool ("isAttacking", false);
 
         if (translation != 0) 
         {
             anim.SetBool ("isWalking", true);
             anim.SetBool ("isIdle", false);
         } 
         else 
         {
             anim.SetBool ("isWalking", false);
             anim.SetBool ("isIdle", true);
         }
 
         if (Input.GetKeyDown ("escape"))
             Cursor.lockState = CursorLockMode.None;
     }
 }


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

1 Reply

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

Answer by Hellium · Mar 30, 2018 at 12:16 PM

      float straffe = Input.GetAxis ("Horizontal") * speed;
      straffe *= Time.deltaTime;

Remove the 2nd line

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 Waraikou · Mar 30, 2018 at 12:33 PM 0
Share

Oh that was that simple :O Thank you !!

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

144 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 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 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 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 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 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

fps script not working 1 Answer

WASD Controls Inverted? 0 Answers

Help on how to code crouching? 0 Answers

What is the problem with the forward motion in this script? 0 Answers

How to handle a Microsoft Controller? C# 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