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
-1
Question by Gaming-Dudester · May 25, 2015 at 07:18 PM · positionmovelookfaceblock

How do I make a block move to another blocks position

WOW lots of different attempts on how to do this(previous questions) this question might work. I have a block(call it block1) and I want it to appear in the other block(block2) position when I look at it no matter where it is(with the first person view).

Comment
Add comment · Show 1
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 ClearRoseOfWar · May 26, 2015 at 09:16 AM 0
Share

I think I understand your question, however if you fully explain your needs it will be easier to help you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by vk007 · May 26, 2015 at 06:24 AM

Use a raycast from the player camera to determine what the player is looking at, and then call a sendMessage() on that object. Then intercept the send message in a script on your Block1 so that it moves to Block2.

Because you asked for a script (though I highly recommend also learning these things for yourself, and in general the answers are not a place to get other people to write scripts for you):

In your camera controller put

 function Update()
 {
   var hit: RaycastHit;
   if(Physics.Raycast(transform.position, transform.forward, hit)) //returns a hit object
   {
      //tell the hit object it was looked at
      hit.transform.SendMessage("Look", SendMessageOptions.DontRequireReceiver); //so we don't get errrors if the message is not caught
   }
 }

And then in your box object have something like:

 var box2: GameObject; //Put box2 into the inspector for this variable
 
 function Look()
 {
   transform.postion = box2.transform.position; //move the current object, Box 1 to box 2
 }

And that should do it.

Comment
Add comment · Show 5 · 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 Gaming-Dudester · May 26, 2015 at 08:36 PM 0
Share

Not what I meant...

avatar image Gaming-Dudester · May 26, 2015 at 08:39 PM 0
Share

I meant the code to do that

avatar image vk007 · May 27, 2015 at 03:41 AM 0
Share

Added example code, it's not tested but should be roughly right.

avatar image Gaming-Dudester · May 27, 2015 at 03:22 PM 0
Share

I'll try it

avatar image Gaming-Dudester · May 27, 2015 at 03:41 PM 0
Share

No it doesn't work :(

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

21 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

Related Questions

How to make a block have highlighted lines like it does in minecraft 2 Answers

Change scripted gui text postion 0 Answers

Button on joystick = move forward 1 Answer

move to a position not being looked at 1 Answer

Vector3.lerp doesn't work 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