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 Alverik · Dec 20, 2016 at 07:01 AM · c#kinematictransform.translateforcesquaternion.slerp

Help convert kinematic style movement to Forces.

Hi, sorry to bother you guys. I'll get to the point: I have this code for moving an object towards a point, it also slowly turns the object towards the target. So, instead of moving in a straight line, the object can curve very nicely, and stray slightly from the path , which looks and feels very nice and gives a more natural movement, specially for flying objects following nodes. But, recently I've been trying to use the code on objects with a rigid body that needs to be nonKinematic during most of runtime (when the object is not flying and just lies in the floor).

Now, I've been changing IsKinematic to true before I start to move the object (right before the loop), and at that point it works, but for some reason, when the code stops and I set IsKinematic back to false, my code is never able to change the rigidbody back to true ever again (if I call the very same function again, the object just wobbles and the inspector shows the rigidbody is not kinematic). Anyone has any idea why that happens? I'm pretty sure I'm not changing IsKinematic anywhere else.

EDIT: Nevermind the above, but if you can help me to get this same effect using forces I'll be really tahnkful. :)

Anyway, I know that there's a penalty for changing Iskinematic in a rigid body, so, else, can anyone tell me what would be the proper way to mimic the same motion but based on physics forces? I must say I've barely used physics based motion before so I'm not sure how I'd get the same effect using forces...

 //right before the loop (note I tried to put this inside the loop too, and no difference)
 if (gameObject.GetComponent<Rigidbody>())
                 gameObject.GetComponent<Rigidbody>().isKinematic=true;
 //inside the loop
 var direction = ActiveNode.transform.position - transform.position;
                 var rotation = Quaternion.LookRotation(direction);
 
                 var tempRotN = _rotationNoise;
                 var tempSpeedN = _movementNoise;
 
                 if (_rotationNoise <= 0) tempRotN = 0.05f;
                 if (_movementNoise <= 0) tempSpeedN = 0.05f;
 
                 var finalTurnSpeed= _turnSpeed + UnityEngine.Random.Range(0.001f, tempRotN);
                 var finalSpeed = _speed + UnityEngine.Random.Range(0.001f, tempSpeedN);
 
                 transform.rotation = Quaternion.Slerp(transform.rotation, rotation, finalTurnSpeed * Time.deltaTime);
                 transform.Translate(new Vector3(0, 0, finalSpeed * Time.deltaTime));
 //right outside the loop (when it's ended)
 if (gameObject.GetComponent<Rigidbody>())
                 gameObject.GetComponent<Rigidbody>().isKinematic = false;
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
Best Answer

Answer by Alverik · Dec 20, 2016 at 11:08 AM

Nevermind about the kinematic issue. Thanks to a guy in the unity forums for making me double check my code. There was a check which depended on a upper level variable, and I didn't notice I wasn't reseting it. Anyway, thanks :)

...Still, if anyone can advise me on how to make this same effect using forces, that'll be swell, heh.

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

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

Making a bubble level (not a game but work tool) 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

buttonNames for GetButton 1 Answer

Transform rotation and position on key input: rotation only working the first time 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