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 /
avatar image
0
Question by Jan_Julius · Oct 24, 2015 at 06:06 PM · movementrigidbodycollidertransforminput

[SOLVED] Object keeps sliding?

My object keeps sliding after transforming it but only on one axis, can someone help me find out why?

https://i.gyazo.com/9ddf7e7fedba70237cc7d956d30ff573.mp4

moving left and right makes it slide continious in the direction it was going and going up and down does not..

 public class Player : MonoBehaviour
 {
     private float turnSpeed = 15f;
 
     private float moveSpeed = 1f;
 
     private Rigidbody rigidbody;
 
     private Collider collider;
 
     public void Awake()
     {
         rigidbody = GetComponent<Rigidbody>();
         collider = GetComponentInChildren<Collider>();
     }
 
     private void FixedUpdate()
     {   
         float v = Input.GetAxisRaw("Vertical");
         float h = Input.GetAxisRaw("Horizontal");
 
         if (
             Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.W) ||
             Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
         {
             Move(h, v);
         }
     }
 
 
     private void Move(float horizontal, float vertical)
     {
         //Rotating(horizontal, vertical);
         MovePlayer(horizontal, vertical);
     }
 
     void MovePlayer(float horizontal, float vertical)
     {
         Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
 
         transform.position += targetDirection * moveSpeed * Time.deltaTime;
     }
 
     void Rotating(float horizontal, float vertical)
     {
         Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
 
         Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
 
         Quaternion newRotation = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSpeed * Time.deltaTime);
 
         rigidbody.MoveRotation(newRotation);
     }
 
 
 }
 
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 toromano · Oct 27, 2015 at 10:27 AM 0
Share

You should make your rigidbody kinematic.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by xainulabdeen · Nov 14, 2018 at 11:19 AM

add physics material to ground and object .sets its friction value to something like 0.6 and set the property rigidbody > interpolate to none

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
avatar image
0

Answer by NightLucididty · Oct 27, 2015 at 10:54 AM

As toromano said, in your comment, Making your rigidbody kinetic should solve the problem, If you dont know where to find the option it on the inspector when you select your player, and look towards the rigidbody part there should be a bool saying is kinetic, or you could enable kinetic rigid body by code using:

 public class ExampleClass : MonoBehaviour {
     public Rigidbody rb;
     void Start() {
         rb = GetComponent<Rigidbody>();
     }
     void EnableRagdoll() {
         rb.isKinematic = false;
         rb.detectCollisions = true;
     }
     void DisableRagdoll() {
         rb.isKinematic = true;
         rb.detectCollisions = false;
     }
 }

I took the code from the unity scripting API, wasn't too hard to find, Good luck with your game, NightLucidity

Comment
Add comment · Show 5 · 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 Jan_Julius · Oct 27, 2015 at 12:07 PM 0
Share

Hey.

I've just been very stupid I didn't realise it till now but I had the character as a child of an object taht would follow it around but just a little slower making it move relative to the parented object..

I've just been stupid sorry.

Jan

avatar image NightLucididty Jan_Julius · Oct 27, 2015 at 01:12 PM 0
Share

Change your title to solved so others know that was your issue.

avatar image Jan_Julius NightLucididty · Oct 27, 2015 at 01:54 PM 0
Share

Oops, my bad. Done now.

Show more comments
avatar image starikcetin · Oct 27, 2015 at 01:19 PM 0
Share

This is too try-hard. You can simply add a high amount of linear drag to rigidbody, so it will stop slowly and will not disable physics interactions.

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

36 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

Related Questions

can not move my enemy with rigidbody 1 Answer

How Do I Create Elastic Ropes For a Wrestling Ring? 1 Answer

How to drag and drop a instantiate prefab on my mobile game 3D using touchs! 0 Answers

How to move an object back/forth on a set path? 2 Answers

Instantiated projectile always floats up 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