Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Cobalt60 · Sep 03, 2012 at 02:47 AM · playerfpsspeedchange

Player moves faster when fps is higher?

Hello Unity community, Cobalt 60 here and I was wondering? why does my player move faster when the frames per second... Like when my game is at 80 fps he moves at the perfect speed. but when I hit 160 fps or higher than 80 or lower than 80 the player's top speed is changed. I have seen tutorials where you add some thing like Time.Deltatime I just want to know how to implement this in thy script lol. here it is if you need some reference.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerControl : MonoBehaviour 
 {
 private GameObject _GameManager;
 public Vector3 movement;
 public float moveSpeed = 6.0f;
 public float jumpSpeed = 5.0f;
 public float drag = 2;
 private bool canJump = true;
 
 void Start()
 {
 _GameManager = GameObject.Find("_GameManager");
 }
 
 void Update () 
 {
 Vector3 forward = Camera.main.transform.TransformDirection(Vector3.forward);
 forward.y = 0;
 forward = forward.normalized;
 
 Vector3 forwardForce = forward * Input.GetAxis("Vertical") * moveSpeed;
 rigidbody.AddForce(forwardForce);
 
 Vector3 right= Camera.main.transform.TransformDirection(Vector3.right);
 right.y = 0;
 right = right.normalized;
 
 Vector3 rightForce= right * Input.GetAxis("Horizontal") * moveSpeed;
 rigidbody.AddForce(rightForce);
 
 if (canJump && Input.GetKeyDown(KeyCode.Space))
 {
 rigidbody.AddForce(Vector3.up * jumpSpeed * 100);
 canJump = false;
 _GameManager.GetComponent().BallJump();
 }
 }
 
 void OnTriggerEnter(Collider other) 
 {
 if (other.tag == "Destroy")
 {
 _GameManager.GetComponent().Death();
 Destroy(gameObject);
 }
 else if (other.tag == "Coin")
 {
 Destroy(other.gameObject);
 _GameManager.GetComponent().FoundCoin();
 }
 else if (other.tag == "SpeedBooster")
 {
 movement = new Vector3(0,0,0);
 _GameManager.GetComponent().SpeedBooster();
 }
 else if (other.tag == "JumpBooster")
 {
 movement = new Vector3(0,0,0);
 _GameManager.GetComponent().JumpBooster();
 }
 else if (other.tag == "Teleporter")
 {
 movement = new Vector3(0,0,0);
 _GameManager.GetComponent().Teleporter();
 }
 }
 
 void OnCollisionEnter(Collision collision)
 {
 if (!canJump)
 {
 canJump = true;
 _GameManager.GetComponent().BallHitGround();
 }
 }
 }
Comment
Add comment · Show 7
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 Cobalt60 · Sep 03, 2012 at 02:48 AM 0
Share

Sorry the script is a confusing $$anonymous$$ESS! :(

avatar image Bunny83 · Sep 03, 2012 at 02:55 AM 2
Share

I would fix it for you, but since the last update here, UA totally messes up the source code of questions. It would be the best when you yould copy your original code again and replace this mess with the original code, but this time don't forget to select everything that is code and press the "101 010" button before you submit. This will indent the selected text and UA will recognise it as code.

Just press the edit button to edit your question.

avatar image Eric5h5 · Sep 03, 2012 at 03:19 AM 1
Share

I can tell from the question title that you need to use Time.deltaTime. The docs explain it quite well, please read them.

avatar image Cobalt60 · Sep 03, 2012 at 06:11 PM 0
Share

Hay thanks Fattie for cleaning my script :D

avatar image Cobalt60 · Sep 05, 2012 at 03:04 AM 0
Share

what do you mean TIC$$anonymous$$ an Answer? :D

Show more comments

1 Reply

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

Answer by Fattie · Sep 03, 2012 at 05:37 AM

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.FixedUpdate.html

"FixedUpdate should be used instead of Update when dealing with Rigidbody"

"For example when adding a force to a rigidbody, you have to apply the force every fixed frame inside FixedUpdate instead of every frame inside Update"

Hopefully that helps out

BTW here's how you make simple timers in U when you're a beginner

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Invoke.html

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to run a script to only 1 player in a multiplayer fps 1 Answer

How do I change what player I want to controll when there is multiple players? 2 Answers

Where is the FPSPlayer Script? 0 Answers

a strange problem ? 1 Answer

Question about FPS Player Script 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