Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Plumcake · Oct 18, 2015 at 04:13 PM · c#scripting problemmovementitweenjerky

Character Movement jerking

Got a problem with my movement script. Please don't send me a movement code that works as i'm trying to learn how to code not just chuck together a game of presets and other people's work!

I'm also using Itween for the movement which is a unity add-on for smooth movement but for some reason my player is really jerky when he moves. It's nothing to do with frame rate as it runs at anything from 30 to 150 and the problem remains. Here's a old video of the which shows the player moving around with the same jerky movement: https://www.youtube.com/watch?v=xdWGNoUeVTw

Code:

using UnityEngine; using System.Collections;

public class PlayerMovement : MonoBehaviour

 {
 public static int playerAnimation;

 public int moveSpeed = 3;

 public static Vector3 playerPosition;
 public static int playerRotation;    //manually set the player rotation
 Transform myTransform;
 public bool running = false;



 void Start()
 {
     myTransform = transform;
     playerAnimation = 0;
 
 }


 void FixedUpdate(){

         //ANIMATION:
 if(playerAnimation == 0)
     {
         GetComponent<Animation>().CrossFade ("Idle", 0.1f);
     }
 if(playerAnimation == 1)
     {
         GetComponent<Animation>().CrossFade ("Walk", 0.1f);
     }

 if(playerAnimation == 2)
     {
         GetComponent<Animation>().CrossFade ("Attack1");
     }

 if(playerAnimation == 3)
     {
         GetComponent<Animation>().CrossFade ("Run");
     }

 if(playerAnimation == 4)
     {
         GetComponent<Animation>().CrossFade ("Death");
     }
     //myTransform.Translate(Vector3.forward * moveSpeed * Input.GetAxis("Vertical") * Time.deltaTime);
     //myTransform.Translate(Vector3.right * moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime);

 if(running == false) {
 if(Input.GetKey("s"))
     {
         playerAnimation = 1;
         myTransform.eulerAngles = new Vector3(0,180,0);
         iTween.MoveBy(gameObject, iTween.Hash("z", 0.25, "speed", 15));
         //    playerPosition = Mathf.Lerp(playerPosition.y, playerPosition.y + 2f,Time.deltaTime);
     }    else if(Input.GetKeyUp("s"))
     {
         playerAnimation = 0;
     }
     }
 if(Input.GetKey("s") && Input.GetKey(KeyCode.LeftShift))
     {
         running = true;
         playerAnimation = 3;
         myTransform.eulerAngles = new Vector3(0,180,0);
         iTween.MoveBy(gameObject, iTween.Hash("z", 0.5, "speed", 15));
     }    else if(Input.GetKeyUp(KeyCode.LeftShift))
     {
         running = false;
     }


 if(running == false){
 if(Input.GetKey("w"))
     {
         playerAnimation = 1;
         myTransform.eulerAngles = new Vector3(0,0,0);
         iTween.MoveBy(gameObject, iTween.Hash("z", 0.25 , "speed", 15));

     }    else if(Input.GetKeyUp("w"))
     {
         playerAnimation = 0;
     }
     }
 if(Input.GetKey("w") && Input.GetKey(KeyCode.LeftShift))
     {
         running = true;
         playerAnimation = 3;
         myTransform.eulerAngles = new Vector3(0,0,0);
         iTween.MoveBy(gameObject, iTween.Hash("z", 0.5, "speed", 15));
     }    else if(Input.GetKeyUp(KeyCode.LeftShift))
     {
         running = false;
     }


 if(running == false){
 if(Input.GetKey("a"))
     {
         playerAnimation = 1;
         myTransform.eulerAngles = new Vector3(0,-90,0);
         iTween.MoveBy(gameObject, iTween.Hash("z", 0.25, "speed", 15));

     }else if(Input.GetKeyUp("a"))
     {
         playerAnimation = 0;
     }
     }
 if(Input.GetKey("a") && Input.GetKey(KeyCode.LeftShift))
     {
         running = true;
         playerAnimation = 3;
         myTransform.eulerAngles = new Vector3(0,-90,0);
         iTween.MoveBy(gameObject, iTween.Hash("z", 0.5, "speed", 15));
     }    else if(Input.GetKeyUp(KeyCode.LeftShift))
     {
         running = false;
     }


 if(running == false){
 if(Input.GetKey("d"))
     {
         playerAnimation = 1;
         myTransform.eulerAngles = new Vector3(0,90,0);
         iTween.MoveBy(gameObject, iTween.Hash("z", 0.25, "speed", 15));

     }    else if(Input.GetKeyUp("d"))
     {
         playerAnimation = 0;
     }
     }
 if(Input.GetKey("d") && Input.GetKey(KeyCode.LeftShift))
     {
         running = true;
         playerAnimation = 3;
         myTransform.eulerAngles = new Vector3(0,90,0);
         iTween.MoveBy(gameObject, iTween.Hash("z", 0.5, "speed", 15));
     }    else if(Input.GetKeyUp(KeyCode.LeftShift))
     {
         running = false;
     }


 if(Input.GetKey("space"))
     {
         playerAnimation = 2;
     }    else if(Input.GetKeyUp("space"))
     {
         playerAnimation = 0;
     }

 if(playerRotation == 1)
     {
         myTransform.eulerAngles = new Vector3(0,90,0);
         playerRotation = 0;
     }

 playerPosition = new Vector3(myTransform.position.x, myTransform.position.y, myTransform.position.z);

 }



}

Thanks for any help in advance!

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

32 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

Related Questions

How to tilt a sprite based on pointer position? 1 Answer

Hexagonal Grid Rangefinding 1 Answer

how do you fix error cs0426 the nested type 'module' does not exist in the type 'unityengine.particalsystem'"? 0 Answers

Input.GetAxisRaw always returns -0.6 1 Answer

Movement Sticking 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