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 /
This question was closed Jun 09, 2018 at 02:29 PM by Tripal for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Tripal · Jun 08, 2018 at 02:00 PM · addforceaddtorqueaddforce movement

Keep current force applied based on Vector3.forward?

Hey, first post on here, I'm curious about how I would achieve this. What I have setup currently is a cube that moves forwards, and rotates using addforce and addtorque. What I'd like to achieve is when there is a current force that's applied to the game object (When a vertical inpuit is held) and the cube is then rotated; the force will continue on based on the front of the cube. Rather than just slide towards where the previous force was pushing to. Similar to how a car would move.

Excuse this rough drawing, but a visual representation may help convey the idea. alt text


The code I currently am using is this.

 rb.AddForceAtPosition((Input.GetAxis("Vertical") * forwardForce * transform.forward), transform.position + addForceLocation, ForceMode.Force);
 rb.AddRelativeTorque(Vector3.up * (Input.GetAxis("Horizontal") * turnForce), ForceMode.Force);


Add a forward force when the vertical input is pressed, times by the desired force in a forward direction, in the root of the rigid body plus the offset.

Rotate torque on the Y axis, by the desired force times by the horizontal input


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

  • Sort: 
avatar image
0
Best Answer

Answer by Tripal · Jun 09, 2018 at 02:28 PM

Found a solution to this for anyone else that comes across this later on. Grip: 0, meaning no traction - 100 decent amount of traction.


 public float grip = 100f;
 Vector3 turningGrip = (Quaternion.Inverse(transform.rotation))* rb.velocity;
 turningGrip.x = Mathf.Lerp(turningGrip.x, 0, Time.deltaTime * grip);
 rb.velocity = transform.rotation * turningGrip;
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

Follow this Question

Answers Answers and Comments

83 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

Related Questions

Torque applied only after force 0 Answers

AddForce Movement Constraint 0 Answers

Animation stops rotation 0 Answers

How to move a rigidbody along a curve or spiral 0 Answers

Smooth movement along an uneven surface 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