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 OshakieGittens61 · Aug 21, 2019 at 05:45 AM · movementrigidbodydrag

How to slow down a gameobject that has rigidbody

I have Player with a rigidbody player script that stops abruptly when i take my off the joystick. However i want it drift forward before stopping

[RequireComponent (typeof (Rigidbody))] public class PlayerController : MonoBehaviour {

 public    LayerMask groundLayers; 
 public CapsuleCollider CapCol;
 private Vector3 JumpMovement;

 private    Rigidbody myRigidbody;
 public Vector3 velocity;
 [SerializeField] float jumpForce;
 private AudioManager audioManager;
 // variable to hold shaking acceleration value
 Vector3 accelerationDir;

 [SerializeField]private GameObject overheadtextSphere;
 // Use this for initialization
 void Start () 
 {
     myRigidbody = GetComponent<Rigidbody> ();

     CapCol = GetComponent<CapsuleCollider> ();

     audioManager = FindObjectOfType<AudioManager> ();


 }

 void Update()
 {
     // Read new acceleration Input from mobile device
     accelerationDir = Input.acceleration;

     /* If you shake the mobile device hard enough
     (accelerations Square Magnitude greater then 5 for example)
     if (accelerationDir.sqrMagnitude >= 4f) 
     {
         Jump ();
     } */

     /*if(Input.touchCount > 0)
     {
         Touch touch = Input.GetTouch (0);
     }*/

 }
  void FixedUpdate() 
 {

    myRigidbody.MovePosition (myRigidbody.position + velocity * Time.fixedDeltaTime);

 /*    if (Input.GetKeyDown (KeyCode.Space) && IsGrounded() )
     {
         
     }*/
         
 }

public void Jump() { jumpForce = 10; if(IsGrounded()) { myRigidbody.AddForce (Vector3.up * jumpForce, ForceMode.Impulse); audioManager.Play ("Jump"); }

 } 
 public bool IsGrounded()
 {
     //.9 is 90% the sphere, jump only if touch the ground
     return Physics.CheckCapsule (CapCol.bounds.center, new Vector3 (CapCol.bounds.center.x, CapCol.bounds.min.y,
         CapCol.bounds.center.z), CapCol.radius * .1f, groundLayers);

 }

 public Vector3 GetPosition()
 {
     return transform.position;
 }
 public void Move(Vector3 _velocity) {

     velocity = _velocity;

 }
 public void LookAt(Vector3 lookPoint) {

     Vector3 heightCorrectedPoint = new Vector3 (lookPoint.x, transform.position.y, lookPoint.z);

     transform.LookAt (heightCorrectedPoint);

 }

}

[RequireComponent (typeof (PlayerController))] public class Player : LivingEntity {

 public float moveSpeed = 5f;
 PlayerController controller;
 Camera viewCamera;
 [SerializeField] VirtualJoystick joystick;
 [SerializeField] GameObject JoyStickbase;

 // Use this for initialization

protected override void Start () { base.Start (); controller = GetComponent (); viewCamera = Camera.main;

     if(Manager.Instance.sceneIndex == 5)
     {
         first_rank_label = KOmode.Instance.rank_text;
         last_rank_label = KOmode.Instance.Lastrank_text;
         playertag = this.gameObject.tag;
         melee_bool = true;

     }
 }
 void Update () 
 {
     Vector3 moveInput = new Vector3 (SimpleInput.GetAxis ("Horizontal"), 0, SimpleInput.GetAxis ("Vertical"));  //controls looking with mouse
 //    Vector3 moveInput = new Vector3(joystick.Horizontal(),0,joystick.Vertical());
     Vector3 moveVelocity = moveInput * moveSpeed;
     controller.Move (moveVelocity);

 /*    if (Time.timeScale < 1)   // To move fast during slowmotion
     {
         controller.Move (moveVelocity*  5); // time gets slowed by 20,so we multiply by 20
     }*/

     Ray ray = viewCamera.ScreenPointToRay (Input.mousePosition);
     Plane groundPlane = new Plane (Vector3.up, Vector3.zero);
     float rayDistance;

     if (groundPlane.Raycast(ray,out rayDistance)) {

         Vector3 point = ray.GetPoint(rayDistance); // point of interception

         controller.LookAt(point);
     }
     if(Input.touchCount > 0)
     {
         Touch touch = Input.GetTouch (0);
         //Vector3 touchPosition = Camera.main.WorldToScreenPoint (touch.position);
         JoyStickbase.transform.position = touch.position;
     }

     Vector3 namePos = Camera.main.WorldToScreenPoint (this.transform.position);

     if(melee_bool)
     {
         if(playertag == KOmode.Instance._firstRankplayer)
         {
             //first_rank_label = KOmode.Instance.rank_text;
             first_rank_label.transform.position = namePos;
         }

         if(playertag == KOmode.Instance._lastRankPlayer)
         {
             //last_rank_label = KOmode.Instance.Lastrank_text;
             last_rank_label.transform.position = namePos;
         }
     }
 
 }
     

}

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 xill · Aug 21, 2019 at 12:41 PM

If I understand right your moveVelocity gets its value from Input. So the value is 0 when there is no Input. Which makes your character

You should not call controller.Move (moveVelocity) all frames that's why your character suddenly stops as velocity becomes 0.

Call it when there is Input. So characters velocity won't be 0 if there is no Input and should decrase overtime with physics.

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 OshakieGittens61 · Aug 22, 2019 at 12:42 AM 0
Share

Yh...…………….. that didn't work :(

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

195 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

Related Questions

Rocket-styled angular drag 0 Answers

Making ball move on drag 0 Answers

Rigidbody movement 1 Answer

Movement of an prefab without rigidbody? 1 Answer

How do I make my Player object move around as if it has high drag (with no sliding), but reacts to knock-back forces as if it has low drag (with lots of sliding)? 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