Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 $$anonymous$$ · Jul 08, 2013 at 07:30 PM · rigidbodyvector3

Rigidbody + Vector3

Is there a way to make a rigidbody go directly to a Position? For Example if my rigidbody is on 0, 0, 0 so it wents straight to lets say 10, 20, 30. I dont want to use Transform.translate, because when i use that the rigidbody wont collide with other rigidbodys.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DavidDebnar · Jul 08, 2013 at 07:40 PM

Use Rigidbody.MovePosition in FixedUpdate().

Edit:

Example 1:

In this example, the rigidbody goes straight to the Destination (10,2,10) with speed of 5 m/s (defined by 'Speed' var). The MinDist variable is there to tell it when to stop, to prevent weird behaviour.

 var Destination : Vector3 = Vector3(10,2,10);
 var Speed : float = 5;
 var MinDist : float = 0.5;
 
 function FixedUpdate () {
     if((Destination - rigidbody.position).sqrMagnitude > MinDist*MinDist)
          rigidbody.MovePosition(rigidbody.position + (Destination-rigidbody.position).normalized*Speed*Time.deltaTime); //Moves the rigidbody to Vector3(10,2,10)
 }

Example2:

In this example, the rigidbody goes in the Direction (1,0.5,1) with speed of 5 m/s (again, defined by 'Speed').

 var Direction : Vector3 = Vector3(1,0.5,1);
 var Speed : float = 5;
 
 function FixedUpdate () {
     rigidbody.MovePosition(rigidbody.position + Direction.normalized*Speed*Time.deltaTime);
 }

--David--

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 $$anonymous$$ · Jul 08, 2013 at 07:48 PM 0
Share

But how do i use this to let a rigidbody go directly to the Vector3?

avatar image
0

Answer by kromenak · Jul 08, 2013 at 07:42 PM

You can try setting Rigidbody.position directly, which is similar to Transform.position, except the position is only applied after the physics steps. I'm not sure whether this means that it will be affected by collision volumes though (you might still get instances where you are stuck halfway in a collider). Still, might be worth a shot.

Another option when you want to move something directly to a position is to use Physics.CheckSphere or Physics.CheckCapsule (or SphereCast/Raycast if more appropriate). Before performing the move, you can check the desired move location (10, 20, 30) with a check/cast function to see whether there are any colliders at that spot. This is best if the Rigidbody you are trying to move is relatively simple (obviously if your Rigidbody is just a Sphere Collider, then the CheckSphere will be perfect), but it can work for more complicated Rigidbodies if you are careful and allow enough buffer.

As far as I know, Rigidbodies will only really perform expected collision detection if you perform continuous movement using either a force or maybe MovePosition function. When you set the position directly, you'll need to perform your own checks to ensure that the spot you are moving to is not occupied by some other collider.

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 zenforhire · Jul 08, 2013 at 08:20 PM

My situation was steering a ship to specific waypoint/position. The physics engine determines the incremental position of the rigidbody. I don't calculate the positions. I wrote a ManeuverComputer to control the rudder and engine to steer it to the position. When the ship's world vector was closing in on intersection with waypoint, I straighten out the controls.

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

17 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

Related Questions

Top Down car/vehicle movement 1 Answer

Joystick to turn object 1 Answer

AddForce to a randomly selected GameObject with a rigidbody 0 Answers

Should I move an object using Transform.translate, or by changing the velocity of the Rigidbody with a Vector2/3 each frame? 0 Answers

Vector3 is always subject to serious stutter in Translation 0 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