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 /
  • Help Room /
avatar image
0
Question by Adagio-81 · Aug 10, 2019 at 03:56 PM · 3dontriggerentertransform.positiontransform.rotation

Moving and rotating object to specific point (3D)

Hi

I hope there are some great people here who can help give me some tips on how to reach my goal

Right now in my game I have a RailroadTrack prefab, where I have placed two tracks on my scene as you can see on the screenshot below. On this prefab I have 6 gameobjects called connectors.

  • Two blue connectors in the center (these are rigidbody and has a sphere collider with a trigger). I'm using this one to test when I'm moving (with my mouse) a track near another track

  • Four yellow connectors (one at each end of the iron-part of the track). My vision is that I'll use these to figure out how to rotate the track

Right now I'm seeing two challenges that I'm unsure how to handle

1) When one of the blue connectors is near another blue connector, I need the position of the blue connector of the other track to be the position where I'll be moving my track to (so the two blue connectors are in the exact same position. Obviously if I'm just setting the transform.position of track I'm moving to the blue connector on the other track, it's not placed correctly. I'm thinking I might need to use the distance I'm getting from subtracting the position of one of the connectors from the other, but I'm not sure how (also taking into consideration that I could connect the track on both sides and the tracks can be in weird angles)

2) When the track I'm dragging around has moved to the other tracks connector, I need to calculate how much it needs to rotate to have the same angle as the other track. Currently I have no idea how to calculate this, so I have created a way that it will rotate 1 degree at a time until the yellow connectors hits each other (unfortunately due to challenge 1, I can't test if this actually works yet, but this is probably still a very bad way of doing it)

Track

EDIT 1: I found the solution for challenge 1 by using the below code when I have the two center connectors that is touching:

 RotateHelper.transform.position = otherCenterConnector.transform.position;
 gameObject.transform.SetParent(RotateHelper.gameObject.transform);
 Vector3 distance =  otherCenterConnector.transform.position - centerConnector.transform.position;
 transform.position+= distance;

track-mission.png (140.2 kB)
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 Adagio-81 · Aug 11, 2019 at 07:29 AM

After playing around with distance I noticed something weird

I have a method that receives both blue center connectors when they are inside trigger area. I then added the following code to see their locations

 Debug.Log("This: " + centerConnector.transform.position.y);
 Debug.Log("Other: " + otherCenterConnector.transform.position.y);

This gives me the following log when they are as close to each as I can do by moving the item with my mouse Log

I did not expect these results at all from position.y. Z and X positions are ok as far as I can see, but the Y is far away. Now my project looks like this. The GhostRailStraight is the one I'm moving around with ConnectTop touch ConnectBottom of TurnedRail. As you can see they are all on the same level and the Y position is set to 0 for both TurnedRail and GhostRailStraight and also for all their sub items (like CenterConnectors, ConnectTop and ConnectBottom)

Where does this -5.9 come from if everything is set to 0? From my understanding transform.position should give the world position. I can see in my sceneview that both center connectors are located at the same place, no matter from where I'm looking at it

Project

EDIT:

Seems like a Unity problem. I created a new object with exactly the same settings, then deleted the old object. Now it works... Weird


trackcentertouchproject.png (6.5 kB)
trackcentertouchlog.png (22.2 kB)
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

205 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

Related Questions

Get camera position back to starting position 0 Answers

object referance not set to instance of an object when accessing transform.position 0 Answers

Velocity of parent local to child 1 Answer

Apply Material to Specific Children 0 Answers

I'm permanently setting a GameObjects positions in Awake() but it keeps moving if I use the Cos function in calculating its position, anyone know why? 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