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 Alex_terrarian · Dec 21, 2020 at 10:09 AM · movementphysicsfriction

My objects are not able to move unless rotation is on

Hi community.

I am fairly new to unity, so I apologise if the solution to this problem is obvious or if my formatting is poor. I am designing a simple code to move my characters along the ground and allow them to jump. However, when they are in contact with the ground, they are unable to move properly. Ideally, the objects should slide across the ground, neglecting friction and without rotation.


I have been testing with three objects:

  • A sphere with rotation restricted

  • A sphere with rotation allowed

  • A cube with rotation allowed alt text

  • The sphere with rotation restricted only moves at the same speed as the other objects in the air, barely moving on the ground.

  • The sphere with rotation allowed rolls across the ground perfectly.

  • The cube flips around the ground like a dice, but in the air does not rotate.


I have tried creating a custom physics material with zero friction for my ground, yet that does not seem to work. Please refer to the code sample and the image below for a better representation of the situation.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AltMotion : MonoBehaviour
 {
     public float jumpVelocity = 100f;
     public float speed = 10f;
     private Rigidbody rb;
     private float velocityY;
     public float gravity = -9.8f;
     private bool isGrounded = false;
     private Vector3 motion;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate()
     {
         //Jumping
         if (Input.GetButtonDown("Jump"))
         {
             velocityY = Mathf.Sqrt(jumpVelocity);
         }
 
         velocityY += gravity * Time.deltaTime;
 
         //Moving
         float xMove = Input.GetAxis("Horizontal") * speed;
         float zMove = Input.GetAxis("Vertical") * speed;
 
         motion = new Vector3(xMove, velocityY, zMove);
         if (motion != Vector3.zero)
         {
             rb.velocity = new Vector3(xMove, velocityY, zMove);
             Debug.Log("x value is " + xMove + " and z value is " + zMove);
         }
     }
 
     void OnCollisionEnter(Collision other)
     {
         if (other.gameObject.tag == "Environment")
         {
             isGrounded = true;
             Debug.Log(isGrounded);
         }
     }
     void OnCollisionExit(Collision other)
     {
         if (other.gameObject.tag == "Environment")
         {
             isGrounded = false;
             Debug.Log(isGrounded);
         }
     }
 }

Thank you for your time!

Edit: I realised that the material properties needed to be applied to both the ground and the object itself for no friction between them, hence allowing them to slide together.

error.png (38.4 kB)
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 Llama_w_2Ls · Dec 21, 2020 at 04:45 PM 0
Share

Can I see a screenshot possibly of the values in your physics material? If the values nullify friction (friction is zero) then you won't need to freeze rotation to prevent the cube from rolling like a dice. @$$anonymous$$_terrarian

avatar image Alex_terrarian · Dec 21, 2020 at 09:20 PM 0
Share

Hi @Llama_w_2Ls , I realised that the physics material needed to be applied to both the ground and the object, rather than just the ground. Thanks for your help!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Alex_terrarian · Dec 21, 2020 at 09:21 PM

I realised that both the ground and the object needed the zero-friction physics material to slide across the ground. This allows for smooth movement across the ground, without the need for rotation.

Comment
Add comment · 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

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

218 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

Related Questions

How to apply friction independent of framerate? 1 Answer

rigidbody friction problem....HELP!! 1 Answer

Object always falling off moving platform 2 Answers

How does Unity want me to add Friction? 0 Answers

My player's movement is slippery 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