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 /
avatar image
0
Question by K_Tec · Aug 02, 2017 at 04:59 PM · scripting problemcharactercontroller

[SOLVED] Character Controller moving at different Framrates?

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 · Show 2
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 Timo326 · Aug 02, 2017 at 11:48 PM 0
Share

One problem is, that when you jump, you do one time "move.y += jumpSpeed;" but many times "move.y -= gravity;". So at 1000 FPS you have much more gravity as if you have 50 FPS.

avatar image K_Tec Timo326 · Aug 03, 2017 at 08:18 AM 0
Share

Hi,

thank you for your answer. But i cant just run move.y -= jumpSpeed at void Start(). Do you think i should put the gravity into FixedUpdate. The problem is that in fixed update player movement fells jittering. I already tryiend move.y -= gravity * Time.deltaTime but it does nothing. It does not makes the gravity frameindependent. Why is that so difficult :(

Regards,

T

4 Replies

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

Answer by K_Tec · Aug 03, 2017 at 11:31 AM

Hello everybody,

i sloved it!! I put all my Code in Fixed Update (even the input) and decreased my fixed timestep to 0.006 Withpout vsync i have now 1100 instaed of 1250 fps thats okay! I only let the code with the health bar in the update method.

Thanks everybody!!!

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
avatar image
0

Answer by Bieere · Aug 02, 2017 at 06:21 PM

If you've already implemented the Time.delta time, you could try setting your rigidbody to Interpolate using interpolate shown below.

It would be helpful to see your CharacterController script as well.

alt text


interpolate.png (12.8 kB)
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 K_Tec · Aug 02, 2017 at 06:28 PM 0
Share

Hi,

thank you for the answer, but this is my Character Controller script. Im moving it in Line 77. $$anonymous$$y Character only has a rigidbody wich is kinematic. But i dont thinkt hat setting it to interpolate will fix that :)

avatar image
0

Answer by Timo326 · Aug 02, 2017 at 08:40 PM

Try to use a Force for jumping. Maybe you can use a target framerate and optimate it on this when you don't need 1000 FPS.

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 K_Tec · Aug 02, 2017 at 08:51 PM 0
Share

Sure i could but its a multiplayer game and if you have 50 or 120 fps makes a big difference. Is there really no way? It hsould work because at cc.move() i used *time.deltaTime, but its still not fra$$anonymous$$depending. Its moving faster on higher fps.

This is amking me mad Please help :((

avatar image
0

Answer by a161803398874 · Aug 02, 2017 at 09:07 PM

time.FixedDeltaTime maybe can help!

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 a161803398874 · Aug 02, 2017 at 09:08 PM 0
Share

in case it doesent ill check the code for now just change it this function it independent of the frame rate

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

121 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

Related Questions

Move CharacterController a specified distance away from starting position. 1 Answer

Make Character Controler can run with diffrent float 1 Answer

After adding script for rotation to look up down, look left right stopped working,After writing code for the rotation for looking up down, looking right left stopped 0 Answers

Boosting Character Controller Problem 0 Answers

How to make a character Jump given a certain condition 2 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