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 whityj375 · Nov 24, 2020 at 12:00 AM · physicsscript.

Character Falling Slower When Moving Back And Forth

I have a simple character controller script that works well accept whenever Im falling and moving in any other direction I fall drastically slower. Im not sure if it has to do with Time.deltaTime and my computer slowing down whenever I move (This shouldnt be the case because I have a nice enough computer (with a decent GPU) to play video games on low settings). Any ideas would be gladly accepted, Thanks!

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Player_Movement_Script : MonoBehaviour
 {
     public Camera camera;
     public GameObject Front_Collider;
     public GameObject Back_Collider;
     public GameObject Left_Collider;
     public GameObject Right_Collider;
     float Player_Gravity = 9.81f / 50;
     float Player_Speed = 0.1f;
     float Sprint_Addition = 0.05f;
     float Sprint_Acceleration = 5;
     float Jump = 65f;
     float Current_Gravity;
     float Current_Speed;
     float Ground_Distance;
     float Ceiling_Distance;
     bool Ceiling_Bool = false;
 
     // Start is called before the first frame update
     void Start()
     {
         Current_Gravity = Player_Gravity;
     }
 
     // Update is called once per frame
     void Update()
     {
         Ray Floor_Ray = new Ray(transform.position, -transform.up);
         RaycastHit Floor_Hit;
 
         if (Physics.Raycast(Floor_Ray, out Floor_Hit))
         {
             Ground_Distance = Floor_Hit.distance - 1;
         }
 
         Ray Ceiling_Ray = new Ray(transform.position, transform.up);
         RaycastHit Ceiling_Hit;
 
         if (Physics.Raycast(Ceiling_Ray, out Ceiling_Hit))
         {
             Ceiling_Distance = Ceiling_Hit.distance - 1;
         }
         else
         {
             Ceiling_Distance = 999;
         }
 
         if (Ceiling_Distance < 0.2f && Ceiling_Bool == false)
         {
             Current_Gravity = Player_Gravity;
             Ceiling_Bool = true;
         }
         if (Ceiling_Distance > 0.2f)
         {
             Ceiling_Bool = false;
         }
 
         if (Ground_Distance > 0)
         {
             if (Ground_Distance > Current_Gravity * Time.deltaTime)
             {
                 transform.position += new Vector3(0, -Current_Gravity * Time.deltaTime, 0);
                 Current_Gravity += Player_Gravity;
             }
             else
             {
                 transform.position += new Vector3(0, -Ground_Distance, 0);
             }
         }
 
         if (Ground_Distance < 0.1f)
         {
             Current_Gravity = 0;
             if (Input.GetKey(KeyCode.LeftShift))
             {
                 Current_Speed = Mathf.Lerp(Current_Speed, Player_Speed + Sprint_Addition, Time.deltaTime * Sprint_Acceleration);
                 camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, 70, Time.deltaTime * Sprint_Acceleration);
             }
             else
             {
                 Current_Speed = Mathf.Lerp(Current_Speed, Player_Speed, Time.deltaTime * Sprint_Acceleration);
                 camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, 60, Time.deltaTime * Sprint_Acceleration);
             }
             if (Input.GetKey(KeyCode.Space))
             {
                 Current_Gravity = -(Player_Gravity * Jump);
                 transform.Translate(0, -Current_Gravity * Time.deltaTime, 0);
             }
         }
 
         if (Input.GetKey(KeyCode.W))
         {
             if (Front_Collider.GetComponent<Collider_Scipt>().Colliding == false)
             {
                 transform.Translate(0, 0, Current_Speed);
             }
         }
         if (Input.GetKey(KeyCode.S))
         {
             if (Back_Collider.GetComponent<Collider_Scipt>().Colliding == false)
             {
                 transform.Translate(0, 0, -Current_Speed);
             }
         }
         if (Input.GetKey(KeyCode.D))
         {
             if (Right_Collider.GetComponent<Collider_Scipt>().Colliding == false)
             {
                 transform.Translate(Current_Speed, 0, 0);
             }
         }
         if (Input.GetKey(KeyCode.A))
         {
             if (Left_Collider.GetComponent<Collider_Scipt>().Colliding == false)
             {
                 transform.Translate(-Current_Speed, 0, 0);
             }
         }
     }
 }
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whityj375 · Nov 24, 2020 at 02:16 AM

ok never mind, I fixed the issue, my ceiling detection was detecting a part of the sprite when moving at high speeds (such as falling) and was triggering a gravity reset. That was causing my fall to be slowed down.

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

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

Arcade Vehicle 0 Answers

How to decrease/(have constant) speed of a ball rolling downhill? 0 Answers

How to make Animation and Physics work together? 2 Answers

problem with wheelcollider 0 Answers

HELP PLEASE PROBLEM WITH JOITS 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