Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 chouchene4561 · Jul 02, 2021 at 08:15 PM · movementprofilerbuild settingstestingfps controller

The Movement Values gets different with higher fps ??

i have an fps controller with some parkour movement and i did build the game i had 300 fps or so and it was unplayable because the gravity value was too hgih and the movement speed was high too but in the other hand i get 60 fps in playmode and it works fine idk what causes it or how to fix it actually my movement system is based on character controller so everything is on the update method should i switch it to fixed update or ? what i want is a constant values regardless of the fps

Comment
Add comment · Show 1
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 DenisIsDenis · Jul 03, 2021 at 02:18 AM 0
Share

If you can show the motion script, then the problem can be cleared up more easily. Perhaps you are not using Time.deltaTime or are using it incorrectly. But the answer depends on how exactly you implemented the movement.

2 Replies

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

Answer by DenisIsDenis · Jul 04, 2021 at 04:06 AM

I have tested your script. Replacing all fixedDeltaTimes with deltaTime solves the FPS dependency problem.


You should never use fixedDeltaTime in the Update() function. After all, this leads to the following consequences:


1) By default FixedUpdate() is called 50 times per second. That is, when using fixedDeltaTime in Update(), normal behavior will only be observed at 50 frames per second.


2) If the user has more than 50 fps, then all script values ​​will be very large (for example, at 500 fps, the values ​​will be 10 times more than normal).


3) If the user has less than 50 fps, then on the contrary, he will have a slowdown, all values ​​will be less than normal (for example, at 25 fps, all values ​​will be 2 times less than normal).


Therefore, I recommend using only Time.deltaTime in the Update() function and achieving smoothness at the expense of Lerp, LerpUnclamped, MoveTowards and RotateTowards functions.

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 chouchene4561 · Jul 04, 2021 at 06:33 PM 0
Share

so if i just use Delta time does that solves the issue of script values ? thanks though

avatar image
0

Answer by chouchene4561 · Jul 03, 2021 at 03:46 PM

@DenisIsDenis some details doesnt matter like states or what ever i used fixed delta time with normal delta time to smooth it a bit but as i said it gets buggy with higher fps even when i used just delta time i faced the same issue and its kinda jerky with just delta time

using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class Movement : MonoBehaviour
 {
     public enum States
     {
         Walking,
         WallRunig,
         Grappling,
         verticalWallRuning,
 
 
     }
     States state;
     [Header("Controller Settings")]
 
     [SerializeField] CharacterController cc;
     [SerializeField] float Movement_Speed;
     [SerializeField] float walkSpeed = 15f;
 
     [SerializeField] float sprintSpeed = 23f;
     [SerializeField] float JumpForce = 15.0f;
     [SerializeField] float CrouchSpeed;
     bool crouching = false;
     [SerializeField] float WallJump = 5f;
     float originalHight;
     [SerializeField] float crouchHight;
     private Vector3 forward, right;
     private Vector3 moveDir = Vector3.zero;
 
 
     bool stopped = false;
     [Header("Gravity")]
     [SerializeField] float CurrentGravity = 13.0f;
     [SerializeField] float NormalGravityOnGround = 14f;
     [SerializeField] float wallJumpGravity = 18f;
     [SerializeField] float wallGravity = .5f;
     [SerializeField] float HookGravity = 19f;
     [SerializeField] [Range(.0f, .5f)] float moveSmoothTime = 0.3f;
     private Vector2 currentDir, currentDirVelocity;
     float velovityY = 0.0f;
     [Header("WallRun")]
     [SerializeField] private float wallSpeed;
     [SerializeField] LayerMask Wall;
 
     [SerializeField] float SideWallforce;
     private Vector3 WallDir;
     private bool Right, left;
     [SerializeField] float Limit;
     private float YonWall;
     [SerializeField] float MaxWallDistance;
     float LWallDistance, RwallDistance;
     RaycastHit Lhit;
     RaycastHit hit;
 
     [Header("Camera")]
     [SerializeField] Camera cam;
     [SerializeField] private float fov;
     [SerializeField] private float wallrunFov;
     [SerializeField] private float wallrunfovTime;
     [SerializeField] private float camTilt;
     [SerializeField] private float camTiltTime;
     [SerializeField] private float GrappleFov;
     [SerializeField] private float GrappleFovTime;
 
 
 
     public float tilt { get; private set; }
     [Header("Grabble")]
     [SerializeField] float GrappleRange;
     [SerializeField] float GrappleSpeed;
     private Vector3 hookPosition;
     [SerializeField] float GrappleJump = 1000f;
     [SerializeField] LayerMask Grapple;
     LineRenderer lr;
 
 
     [Header("vertical Wallrun settings")]
 
     [SerializeField] private float VerticalgravityForce = 5f;
     Vector3 verticalWallRunDirection = Vector3.zero;
     public LayerMask verticalWRLayer;
     [SerializeField] float maxcastdistance;
     bool JumpedFromWall = false;
     [SerializeField] float verticalWallSPeed = 10f;
     [SerializeField] float CLimbingJump = 750f;
     RaycastHit vhit;
     private void Awake()
     {
         lr = GetComponent<LineRenderer>();
     }
     void Start()
     {
         originalHight = cc.height;
         state = States.Walking;
     }
     private void LateUpdate()
     {
         if (state == States.Grappling)
         {
             DrawRope();
         }
 
     }
     private void Update()
     {
         if (state == States.Walking)
         {
 
             movementInput();
             normalMovement();
             Crouch();
             sprint();
             resetfov();
             lr.positionCount = 0;
 
         }
 
         else if (state == States.WallRunig)
         {
             wallruning();
 
 
         }
         else if (state == States.Grappling)
         {
             GrappleOnAir();
         }
         else if (state == States.verticalWallRuning)
         {
             VerticalWallrun();
         }
 
 
         RwallDistance = Vector3.Distance(transform.position, hit.point);
 
 
 
         LWallDistance = Vector3.Distance(transform.position, Lhit.point);
 
 
 
         float vWallDistance = Vector3.Distance(transform.position, vhit.point);
 
         if (stopped && cc.isGrounded)
         {
             stopped = false;
         }
         else if (stopped && LWallDistance >= MaxWallDistance && RwallDistance >= MaxWallDistance)
         {
             stopped = false;
         }
 
 
         if (JumpedFromWall && cc.isGrounded)
         {
             JumpedFromWall = false;
         }
         else if (JumpedFromWall && vWallDistance >= MaxWallDistance)
         {
             JumpedFromWall = false;
         }
 
         checkWall();
         GrappleCheck();
 
         //checking for vertical climbing; 
         if (Physics.Raycast(cam.transform.position, cam.transform.forward, out vhit, maxcastdistance, verticalWRLayer) && !JumpedFromWall && !cc.isGrounded)
         {
             state = States.verticalWallRuning;
         }
 
 
     }
 
 
     void movementInput()
     {
 
         Vector2 Targetdir = new Vector2(Input.GetAxisRaw("Horizontal"),
       Input.GetAxisRaw("Vertical"));
         Targetdir.Normalize();
         currentDir = Vector2.SmoothDamp(currentDir, Targetdir, ref currentDirVelocity, moveSmoothTime);
         if (cc.isGrounded)
         {
             velovityY -= CurrentGravity * Time.fixedDeltaTime;
             CurrentGravity = NormalGravityOnGround;
 
         }
         if (!cc.isGrounded)
         {
             velovityY -= CurrentGravity * Time.fixedDeltaTime;
 
         }
 
         if (Input.GetButtonDown("Jump") && cc.isGrounded) velovityY = JumpForce * Time.fixedDeltaTime;
 
 
 
         cc.Move(moveDir * Time.fixedDeltaTime);
     }
     void normalMovement()
     {
         forward = cam.transform.forward.normalized;
         right = transform.right.normalized;
 
         moveDir = (forward * currentDir.y + right * currentDir.x) * Movement_Speed;
         moveDir.y = velovityY;
 
 
 
     }
     void Crouch()
     {
         if (Input.GetKey(KeyCode.C))
         {
             crouching = true;
         }
         else crouching = false;
 
         if (crouching)
         {
             cc.height = crouchHight;
             Movement_Speed = CrouchSpeed;
         }
         else if (!crouching)
         {
             cc.height = originalHight;
             Movement_Speed = walkSpeed;
         }
     }
     void sprint()
     {
         if (Input.GetKey(KeyCode.LeftShift))
         {
 
             Movement_Speed = sprintSpeed;
 
         }
         else if (Input.GetKeyUp(KeyCode.LeftShift))
         {
             Movement_Speed = walkSpeed;
         }
     }
 
     void checkWall()
     {
         if (Physics.Raycast(transform.position, transform.right * SideWallforce, out hit, Limit, Wall) && !cc.isGrounded && !stopped)
         {
 
             Right = true;
             left = false;
 
             WallDir.y = YonWall;
             YonWall = wallGravity * Time.fixedDeltaTime;
             state = States.WallRunig;
 
         }
 
 
 
 
 
         else if (Physics.Raycast(transform.position, -transform.right * SideWallforce, out Lhit, Limit, Wall) && !cc.isGrounded && !stopped)
         {
             left = true;
             Right = false;
 
 
             WallDir.y = wallGravity * Time.fixedDeltaTime;
             state = States.WallRunig;
 
 
         }
         else
         {
             Right = false;
             left = false;
             state = States.Walking;
         }
 
 
 
 
 
     }
     void startwallrun()
     {
         cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, wallrunFov, wallrunfovTime * Time.deltaTime);
 
         if (Right == true)
         {
             WallDir = (forward * wallSpeed + right * SideWallforce);
             tilt = Mathf.Lerp(tilt, camTilt, camTiltTime * Time.deltaTime);
 
         }
         else if (left == true)
         {
             WallDir = (forward * wallSpeed + -right * SideWallforce);
             tilt = Mathf.Lerp(tilt, -camTilt, camTiltTime * Time.deltaTime);
         }
 
         cc.Move(WallDir * Time.deltaTime);
 
     }
     void stopWallrun()
     {
         state = States.Walking;
         Right = false;
         left = false;
         stopped = true;
 
 
 
     }
     void wallruning()
     {
 
 
         startwallrun();
 
 
 
         if (Input.GetButtonDown("Jump"))
         {
 
 
 
 
             stopWallrun();
 
             velovityY = WallJump * Time.fixedDeltaTime;
             moveDir.y = velovityY;
 
 
 
 
 
 
             CurrentGravity = wallJumpGravity;
 
 
 
         }
 
 
 
 
         else if (!Right && !left)
         {
             stopWallrun();
 
         }
     }
     void resetfov()
     {
         cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, fov, wallrunfovTime * Time.deltaTime);
         tilt = Mathf.Lerp(tilt, 0, camTiltTime * Time.deltaTime);
 
 
     }
 
     void GrappleCheck()
     {
 
 
         if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit, GrappleRange, Grapple) && Input.GetKey(KeyCode.E))
         {
             hookPosition = hit.point;
 
             state = States.Grappling;
 
 
 
         }
 
     }
 
     void GrappleOnAir()
     {
         cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, GrappleFov, GrappleFovTime * Time.deltaTime);
         velovityY = -1f * Time.deltaTime;
         Vector3 GrappleDirection = (hookPosition - transform.position).normalized;
         cc.Move(GrappleDirection * GrappleSpeed * Time.deltaTime);
 
         if (Input.GetKeyUp(KeyCode.E))
         {
             velovityY = GrappleJump * Time.fixedDeltaTime;
 
 
             CurrentGravity = HookGravity;
             moveDir -= hit.normal * GrappleJump;
 
         }
         if (Vector3.Distance(transform.position, hit.point) >= 10f)
         {
             velovityY = GrappleJump * Time.fixedDeltaTime;
             moveDir -= hit.normal * GrappleJump;
 
             state = States.Walking;
 
         }
 
     }
     void DrawRope()
     {
 
         lr.enabled = true;
         lr.positionCount = 2;
         lr.SetPosition(0, transform.position);
         lr.SetPosition(1, hookPosition);
 
     }
 
 
 
     void VerticalWallrun()
     {
         StartverticalWallrun();
 
 
         velovityY = -1f;
 
 
     }
     void StartverticalWallrun()
     {
 
         cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, wallrunFov, wallrunfovTime * Time.deltaTime);
         verticalWallRunDirection = (forward * VerticalgravityForce + transform.up * verticalWallSPeed) * Time.deltaTime;
         cc.Move(verticalWallRunDirection * Time.fixedDeltaTime);
         if (Input.GetButtonDown("Jump"))
         {
             stopverticalWallrun();
             JumpedFromWall = true;
             velovityY = CLimbingJump * Time.fixedDeltaTime;
             moveDir.y = velovityY;
         }
 
     }
     void stopverticalWallrun()
     {
         JumpedFromWall = true;
 
 
         state = States.Walking;
     }
     private void OnTriggerEnter(Collider other)
     {
         if (other.CompareTag("Finish") && state == States.verticalWallRuning)
         {
             stopverticalWallrun();
             JumpedFromWall = true;
             velovityY = CLimbingJump * Time.fixedDeltaTime;
             moveDir.y = velovityY;
 
         }
     }
 
 }
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

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

frame rate drops when going to maximise 0 Answers

When I go to test my game I press the keys I have assigned to move my fp capsule I cant move. WHY NOT? 0 Answers

VR FPS controller dosen't work on android 1 Answer

How Do I Get My Player To Move With The Block That Its On 1 Answer

Character sometimes moves faster when I jump and start moving at the same time 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