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 /
avatar image
0
Question by Aslan_Sumankalpa · Feb 11, 2021 at 05:08 PM · rigidbodytransformproblem during runtimemovements

How do I fix my FPS movement Script?

So, I followed a tutorial for the movement and the looking, then I applied sliding, with this code:

//Sliding if(Input.GetKey(KeyCode.LeftControl)) { transform.localScale = new Vector3 (1, slideHeight, 1); }else { transform.localScale = new Vector3 (1, normalHeight, 1); }

But then, I can't jump, and the layer mask function (for finding out if there is ground beneath the player) doesn't work. I tried deleting the sliding code, but it still didn't work.

Full code:

 private Rigidbody rb;
 
 public LayerMask layerMask;
 public bool grounded = true;
 public bool isJumpBoost = false;
 
 public float moveSpeed = 6;
 public float slideHeight = 0.5f;
 public float normalHeight = 1.5f;
 
 public float normalJump = 10f;
 public float jumpForce = 10;
 public float boostJump = 30f;
 
 public float maxFall = -55;
 
 // Start is called before the first frame update
 void Start()
 {
     rb = GetComponent<Rigidbody>();
 }

 
 // Update is called once per frame
 void Update()
 {
     float x = Input.GetAxisRaw("Horizontal") * moveSpeed;
     float y = Input.GetAxisRaw("Vertical") * moveSpeed;
     
     grounded = Physics.CheckSphere(new Vector3(transform.position.x, transform.position.y - 1, transform.position.z), 0.4f, layerMask);
     
     if(Input.GetKeyDown(KeyCode.Space) && grounded)
         rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
     
     Vector3 movePos = transform.right * x + transform.forward * y;
     Vector3 newMovePos = new Vector3(movePos.x, rb.velocity.y, movePos.z);
     
     rb.velocity = newMovePos;
     
     
     
     if(gameObject.transform.position.y <= maxFall)
     {
         Debug.Log("Player is falling");
         Time.timeScale = 0f;
         //Lose();    
     }
     
     
     //Sliding
     if(Input.GetKey(KeyCode.LeftControl))
     {
         transform.localScale = new Vector3 (1, slideHeight, 1);
     }else
     {
         transform.localScale = new Vector3 (1, normalHeight, 1);
     }
 
 
 }
 
 //Collision Detection
         void OnCollisionEnter(Collision col)
     {
         
         if(col.collider.name == "jumpBoost")
         {    
         jumpForce = boostJump;
         Debug.Log("Player gets a jump boost");
         isJumpBoost = true;
         
         }else
         {
             jumpForce = normalJump;
             Debug.Log("No jump boost now");
             isJumpBoost = false;    
         }
         
     }
 
     //void Lose() this is a function
     //{
             
     //}
 
 

}

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

177 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

Related Questions

Intercepting Alghorithm not wok properly 1 Answer

Why is the if condition returning true ? 0 Answers

Flinging Wall Death 1 Answer

Anti-Gravity vehicle bounce-back help. 1 Answer

My character moves under the terrain at strange Y position 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