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 K_Tec · Aug 02, 2017 at 04:14 PM · scripting problemcharactercontroller

Character Controller moving at different Framrates? [Unsolved]

Hello Everybody,

i have a problem: my Character controller is moving as it should at 1000FPS but at 60 it jump too height, the camera head bob is not working and he is walking too slow. I already searched in Unity answers, but i dont found a solution. At my cc.Move(move * Time.deltaTime) i alread implemented delta time and it should be the same at all frames but it is not! This is a very serious problem for my game. I know i could do all in FixedUpdate and the Input in Update but it will move jittering in Fixed Update! Please give me a tip to fix that :(

Best Regards, and Thanks in advance!!

T

Heres my Code:

 public CharacterController cc;
 public float walkSpeed;
 public float runSpeed;
 public float crouchSpeed;
 public float gravity;
 public float jumpSpeed;
 public bool canControl;


 //health
 public float health;
 public float Energy;
 public float energyIncrease;
 public float canSurviveFall;
 public float fallDamage;
 public float energyIncreaseTime;
 public float jumpEnergyCost = 200f;
 public float sprintEnergyCost = 1f;


 //HUD
 public Image healthBar;
 public Image energyBar;

 //private variables
 private float X;
 [HideInInspector]
 public float remainingHealth;
 [HideInInspector]
 public float remainingEnergy;
 private bool canRun;
 private bool canJump;
 private float Z;
 private float falledDistance;
 private Vector3 lastPos;
 public Vector3 move = Vector3.zero;

 public int movementState = 0; //0 standing , 1 walking , 2 running , 3 air , 4 crouching

 void Start()
 {
 remainingHealth = health;
 remainingEnergy = Energy;
 canJump = true;
 }
 void Update ()
 {
 if (cc.isGrounded && canControl)
 {
 move = new Vector3(Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical"));
 move = transform.TransformDirection(move);
 move *= walkSpeed;
 movementState = 1;
 remainingEnergy += energyIncrease;
 //if the player is walking or crouching it does not cost any energy




 if (Input.GetButton("Sprint") && canRun && remainingEnergy > 1)
 {
 move *= runSpeed;
 remainingEnergy -= sprintEnergyCost;
 movementState = 2;
 }

 if ( Input.GetButtonDown("Jump") && canJump && remainingEnergy > 300)
 {
 move.y += jumpSpeed;
 remainingEnergy -= jumpEnergyCost;
 movementState = 3;
 }

 if (Input.GetButton("Crouch"))
 {
 cc.height = 1;
 move /= crouchSpeed;
 movementState = 4;
 canRun = false;
 }

 else
 {
 cc.height = 2;
 canRun = true;
 }

 }
 healthBar.fillAmount = remainingHealth/ 100;
 energyBar.fillAmount = remainingEnergy / 1000;
 move.y -= gravity;
 cc.Move(move * Time.deltaTime);


 if (remainingHealth < 1)
 {
 remainingHealth = 0;
 Die();
 }

 if (remainingEnergy < 0)
 {
 remainingEnergy = 0;
 }

 if (remainingEnergy > Energy)
 remainingEnergy = Energy;

 if (!cc.isGrounded)
 {
 movementState = 3;
 }

 }


 void Die()
 {
 Destroy(gameObject);
 }
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

160 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 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 do I make player attack with LMB if the enemy is within range? 0 Answers

How to make a character Jump given a certain condition 0 Answers

Isometric Movent Issue 0 Answers

Jumping with slight air control while retaining velocity 1 Answer

Character's jumping mechanism stuck into something invisible 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