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 JaydenHilton · Apr 14, 2021 at 04:41 AM · collisionmovementcharactercontroller

issue applying vector for slope sliding

trying to implement crouch sliding in my game down slopes above some threshhold (meaning that the player should speed up if they are facing around the direction of the slope going down.) I am also trying to implement sliding down slopes above 80 deg.

Having trouble adding the vector of the slope to the player velocity so that they actually slide down. My current code launches the player upwards when they hit a slope with any velocity, and I know that its because of how I'm applying the slope vector but I'm not sure how else to do it. Any help greatly appreciated, code below:

 void OnControllerColliderHit(ControllerColliderHit hit)
     {
         if (hit.gameObject.layer == 3)
         {
             //calculates the downslope vector of the surface at the point of contact
             Debug.DrawLine(transform.position, hit.point, Color.red);
             hitNormal = hit.normal;
             hitTransform = hit.transform;
             groundAngle = Vector3.Angle(Vector3.up, hitNormal);
             Vector3 axis = Vector3.Cross(Vector3.up, hitNormal);
             slopeVector = Quaternion.AngleAxis(90 + groundAngle, axis) * Vector3.up + transform.position;
 
             Debug.DrawLine(transform.position, slopeVector, Color.green);
             Debug.DrawLine(transform.position, velocity + slopeVector, Color.blue);
             print("Slope Velocity Vector: " + (velocity + slopeVector));
         }
     }

 void FixedUpdate()
     {
         isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, collidable);
         print(isGrounded);
         velocity.x = velocity.x / setSpeed;
         velocity.z = velocity.z / setSpeed;
         //add gravity and frictional/sliding forces to the vector then apply
         if(isGrounded && !Input.GetButtonDown("Jump"))
         {
             if (hitTransform != null)
             {
                 if(hitTransform.position.y <= transform.position.y)
                 {
                     if(isCrouching && Vector3.Angle(velocity, slopeVector) < 70)
                     {
                         velocity = slopeVector;
                     }
                     else if (groundAngle >= 50)
                     {
                         velocity = slopeVector;
                     }
                 }
             }
         }
         else
         {
             velocity.y += gravity * Time.deltaTime;
         }
 
         controller.Move(velocity * Time.deltaTime);
     }

Thank you for taking the time to read through my question, I hope that I have made it clear.

Comment
Add comment · Show 1
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 JaydenHilton · Apr 15, 2021 at 08:03 PM 0
Share

I forgot to mention, for slope sliding, I tried to just multiply the slope vector by some scalar, to make it larger than the velocity of the character moving, but it did not work well. I think I just have some gaps in my understanding of vectors, but I'm still struggling even after reading over the documentation. I understand that vectors are position values with a direction cast from the origin and I guess where I'm struggling is how to apply a vector to my player which is centred in the player's transform, still incorporates movement input from the player, and results in a force that pushes them down the slope. Maybe I can figure it out if I just keep trying to brute force it.

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

229 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

Related Questions

Why does my character fly upwards when I click play? 1 Answer

How to hold objects in third person? 1 Answer

Using rigidbody for collisions only, not movements? 1 Answer

My character can stop movement of the Death Star! 2 Answers

CharacterController.Move() is causing unwanted vertical movement . . . how to fix? 2 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