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 gusdnjf98 · Jan 13 at 03:14 PM · movementrigidbody.velocity

Problem Movement with Rigidbody.velocity

As shown in the figure, the capsule continues to move in the +x direction (the direction of another collision object).

The problem is that gravity does not work properly in this case.

alt text

Rigidbody.Gravity was basically used. If there is no collision except for the floor, it works correctly.

Therefore, it is not a solution to use a high value of custom gravity.

As a result of analyzing Rigidbody.Info,

  1. Move the Capsule in the +x and +y directions.(OK)

  2. Collides with another object.(OK)

  3. Rigidbody.velocity.x changes to zero. (OK)

  4. Rigidbody.velocity.y changes close to zero. (Why?)

I ask for help like this due to lack of knowledge.

It can be awkward because I used a translator.

 public class Movement : MonoBehaviour
 {
     Vector2 direction = Vector2.zero;
     Vector3 velocity = Vector3.zero;
     Rigidbody rb;
 
     [SerializeField]
     private float speed = 3f;
     [SerializeField]
     private bool isJumpPressed;
     [SerializeField]
     private float jumpHeight = 2f;
 
     private void Awake()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     private void FixedUpdate()
     {
         Move();
         Jump();
     }
 
     private void Jump()
     {
         if (!isJumpPressed) return;
         
         velocity.Set(velocity.x, jumpHeight, velocity.z);
         rb.velocity = velocity;
     }
 
     private void Move()
     {
         velocity.Set(direction.x * speed, rb.velocity.y, 0f);
         rb.velocity = velocity;
     }
 
     #region Input Events
 
     public void OnMove(InputAction.CallbackContext value)
     {
         direction = value.ReadValue<Vector2>();
     }
 
     public void OnJump(InputAction.CallbackContext value)
     {
         if (value.performed)
             isJumpPressed = true;
         else
             isJumpPressed = false;
     }
 
     #endregion
 }
 


스크린샷97.png (290.0 kB)
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 Lenny_N · Jan 15 at 06:07 PM

im new to coding and i dont rlly know much but i try putting a physics material on the wall and then turned it all to 0 and minimum and it worked fine exept when i walk into a wall i cant jump anymore until i walk into a wall again here my jumping script: public float Force;

  private bool grounded = true;
  
  void OnCollisionEnter(Collision collision)
  {
      grounded = true;

  }
  void OnCollisionExit(Collision other)
  {
     grounded = false;
  }

 void Update()
 {
     if(grounded == true)
     {
        if (Input.GetKeyDown("space"))
         {
          GetComponent<Rigidbody>().velocity = new Vector3(0, Force, 0);
         }
     }

     if(grounded == false)
     {
         return;
     }
 }
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 gusdnjf98 · Jan 16 at 01:07 PM 0
Share

Thank you for your answer. But this code is not available. Your code is simply considering jumping. This is completely different from the direction of the solution I want.

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

233 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

Related Questions

Moving and Rotating Rigidbody in a responsive way 2 Answers

Rigidbody.velocity is rotating instead of moving my character? 0 Answers

First Person Slide in direction of rigidbody movement and not look direction 1 Answer

Rigidbody2D.velocity Won't Move Object 3 Answers

Stop Movement On Trigger 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