Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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 rrtenz · 2 days ago · rigidbodyterraintransform.position

Game Object seems to move on it's own

I have a GameObject that I am moving along a baked terrain. I do this by clicking, setting a'destination' object where I click, and then telling the player object to move to the destination. I am now trying to get the object to "warp" from one location on the terrain to another, but when I do this it briefly appears in the desired location and then warps to a random location. I have posted a video here to show the behavior: https://youtu.be/WtmzBLMi9FE

To "warp" the object, I am modifying the transform.position by changing the X and Z coordinates to the desired location and then using a Physics.Raycast for the Y coordinate:

 mainPlayerObject.transform.position = GetRandomStartingLocation(StartLocation.transform.position, -10f, 10f);    
     Vector3 GetRandomStartingLocation(Vector3 pos, float min, float max)
     {
         RaycastHit hit;
         int attemptCount = 0;
 
         while (attemptCount <= 10)
         {
             float x = UnityEngine.Random.Range(min, max) + pos.x;
             float z = UnityEngine.Random.Range(min, max) + pos.z;
 
             Vector3 position = new Vector3(x, 0, z);
             //Do a raycast along Vector3.down -> if you hit something the result will be given to you in the "hit" variable
             //This raycast will only find results between 'min' and 'max' units of your original "position"
             if (Physics.Raycast(new Vector3(0, max, 0) + position, Vector3.down, out hit, max - min))
             {
                 return hit.point;
             }
             else
             {
                 Debug.Log("there seems to be no ground at this position");
             }
 
             attemptCount++;
         }
 
         return pos;
     }

As I mentioned, this code moves the object to where I would like it for a moment and then it moves to a random location. I originally put breakpoints all throughout my code to see why this was happening, but I haven't been able to discover the culprit. I eventually bought this debug tool from the Asset Store. It is a tool that keeps track of where transforms are being manipulated. I ran a test where I was continually sending my object to the desired location and it showed that the position was being changed continually by an unknown script (possibly Unity Rigid Body or Physics code). I have attached an image with the results I don't know if I'm doing something wrong or if I have a misunderstanding of Rigid Bodies, Baked Terrains, or something else, but something really wants my object to be in a position other than where I'm telling it to be. If you have any ideas, please let me know. Thanks! alt text

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

0 Replies

· Add your reply
  • Sort: 

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

134 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

Related Questions

Terrain and Rigidbody2D incompatible for XZ Topdown?,Using RigidBody2D and Terrain incompatible in top-down game? 0 Answers

Managing collision with transform movement 0 Answers

Import problem with Blender3d 2 Answers

I'm trying to create a Flying bird and when you stop pressing up arrow you lose height when you start pressing again up arrow you return to your original height. 1 Answer

Rigidbody below terrain getting dragged 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