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 ZinByakuya · Jun 09, 2015 at 05:42 AM · c#collisionphysicsground

How to Clamp A RigidBody to the Ground/ Moving a RigidBody Along the Ground

Hello! this is my very first Question here!/sorry for my english.

Currently I am writing a RigidBody Character Controller, and I'm having some trouble.

if I move the RB on a flat surface everything is fine, but as soon as there is a slope (like 20°),

it starts to go forward, then its in the air and falls to the ground, then it detects the Ground and falls again, it moves like on stairs, but its a steady slope.

Now I want that the RB moves along the Ground, but stays upright. I already have a version of that working, but the Capsules Y Axis just alligns with the Normal.

I'm adding the Code snippet that allows me to do that. ( its not just Capsule.up = Ground.normal)

 void FixedUpdate () 
     {
         // ControllerInput
         float DirH = Input.GetAxis("LSX");
         float DirV = Input.GetAxis("LSY");
 
          DetectGround();  //SphereCast Down, Mathf.Infinity, measures distance.
 
          if (onGround == true)
         {
             if (DirH != 0 || DirV != 0)
             {
                 flippedCharCamera = (CharCamera.forward * -1);     //CharCamera is the Main Camera
                 CharDirection = DirV * flippedCharCamera + DirH * CharCamera.right;                // Calculation of the Movement
                 expectedPlayerPosition = CharRb.transform.position + CharDirection * charSpeed * Time.deltaTime;    // Expected Player Position, CharRb is the RigidBody Character Controller
 
  Physics.Raycast(Player.position, CharDirection - (Player.up + new Vector3(0, 2f, 0)), out AddGroundInfo, Mathf.Infinity, CharMask);    //CharMask ignores the Layer the Controller is in
 
 Vector3 MagentaDirection = (groundSphereInfo.point - AddGroundInfo.point) * -1;   //groundSphereInfo is the RaycastHIt of the SphereCast in DetectGround();
                     CharDirection = Vector3.Project(CharDirection, MagentaDirection);
                     CharRb.MovePosition(CharRb.transform.position + CharDirection * charSpeed * Time.deltaTime);   //charSpeed is a float 12f;
 
 }
 }
 }
 
 
 

I am stuck at this... please send help!

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 Mark Gossage · Jun 09, 2015 at 06:46 AM 0
Share

Is this a 2D or 3D? If its 2D, why not look at http://unity3d.com/learn/tutorials/modules/beginner/2d/2d-controllers If its 3D, why not use a character controller?

avatar image ZinByakuya · Jun 09, 2015 at 07:20 AM 0
Share

it is 3D, and I already decided on a Rigid Body, because it has to simulate physics. I am going to do some unusual stuff with the Controller, and I can't do that with the CHaracter Controller.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to change CC script to Rigidbody script 1 Answer

Objects not colliding twice 0 Answers

Handling colliders on hundreds of asteroids (not procedural asteroids) ...URGENT 3 Answers

Physics.IgnoreCollision by Tag question 2 Answers

How to hit objects in VR 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