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 /
  • Help Room /
avatar image
0
Question by Tashanova · Mar 08, 2018 at 06:39 PM · movementcharactercontrollervelocityjump

Using Velocity breaks my jumping

Hey guys I'm having a problem with my playercontroller.

For some reason when I use rb.velocity it breaks my jumping. How it breaks my jumping is by, when pressing "Jump" the player automatically goes to the maximum jump height then falls back. There seems to be a limit on the jump height unless I massively change the "Jumpforce" by a large number it will not change.

I have tried to fix this problem myself, I changed the movement to a simple WASD movement with a transform.position and the jump mechanic worked fine. Then I thought it was the MagnitudeClamp so I removed that and the outcome was the same.

public class PlayerController : MonoBehaviour {

 public float newspeed = 10f;
 float jumpforce = 5f;
 public bool isMoving;
 public bool isRunning;
 //public Transform groundcheck;
 private Rigidbody rb;
 public LayerMask groundlayer;
 public bool isGrounded;
 public Vector3 jump;

 void Start()
 {
     rb = GetComponent<Rigidbody>();
     Cursor.lockState = CursorLockMode.Locked;
     jump = new Vector3(0.0f, 10.0f, 0.0f);

 }
 private void Update()
 {
     RaycastHit hit;
     if (Physics.Raycast(transform.position, -Vector3.up, out hit))
     {
         if (hit.distance < 0.51f)
         {
             isGrounded = true;
         }
         else
         {
             isGrounded = false;
         }
     }
     if ((Input.GetButtonDown("Jump")) && (isGrounded))
     {
         //Jump using the rigidbodies force of gravity.
         rb.AddForce(jump * jumpforce, ForceMode.Impulse);
         
     }

 }

 void FixedUpdate()
 {

     rb.velocity = Vector3.ClampMagnitude((rb.transform.forward * Input.GetAxis("Vertical") * newspeed) + (rb.transform.right * Input.GetAxis("Horizontal") * newspeed), newspeed);
     Physics.gravity = new Vector3(0, -50f, 0);
     isMoving = false;
     isRunning = false;
 }



Thank you for reading my thread

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 MaxGuernseyIII · Mar 08, 2018 at 07:43 PM 0
Share

$$anonymous$$y eye keeps being drawn to where you directly set velocity in your FixedUpdate method. It seems like it should override whatever AddForce did, previously. While that doesn't directly create the effect you are seeing, it makes me wonder if there is some other place where you are directly setting a variable (like position, perhaps) that is causing this. $$anonymous$$aybe something in code you haven't posted?

avatar image Tashanova MaxGuernseyIII · Mar 08, 2018 at 07:52 PM 0
Share

I don't access the position anywhere else in the code, the only part that I do is in a mouse rotation script which moves the characters rotation but when disabling that to see if it affects anything it has no affect

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

125 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

Related Questions

Fix for inconsistent jump height? 1 Answer

Double Jump using character controller 0 Answers

Problem with Jump script 1 Answer

Jump logic issues 0 Answers

Gravity To CharacterController 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