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 /
This question was closed Feb 28, 2015 at 01:30 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Nuno · May 09, 2011 at 02:01 AM · raycastcoordinates

Move object to specific coordinates

Hi i need a little help on raycast, if there anyone ill appreciate.

What i have so far and what ive want to do:

I have an Gameobject(myplayer) in a terrain with a camera to follow (myplayer), i have a script that allow me to select things and know what object are selected (raycast).

Now what im trying to do is, when my player are selected, i want to move it to a certain point on terrain with Input.Mousebutton, but i dont know how the best way to do this...

ive tried to create a simple test with

var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);

*myplayer.trsansform.position = Vector3(Input.mousePosition.x,Input.mousePosition.y,Input.mousePosition.z);

but that doesnt work, myplayer disapears from screen and the y keeps increse.

so ive decided to ask if its a method with coordinates, that we can grab input.mouseposition when and where weve clicked, and myplayer to go to those coordinates?

Something like this:

var ray: coordinates

myplayer.transform.position = Vector3(ray.x,ray.y,ray.z);

...

Thank you

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 Dreamer · May 09, 2011 at 02:21 AM

You could refer to below script, it shows how to move your object to a location when mouse clicked using Raycast.

http://www.unifycommunity.com/wiki/index.php?title=Click_To_Move

edit: Site was moved :

http://wiki.unity3d.com/index.php?title=Click_To_Move

Comment
Add comment · Show 2 · 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 Nuno · May 09, 2011 at 02:25 AM 0
Share

going to check thank you for fast reply ;)

avatar image Nuno · May 09, 2011 at 02:57 AM 0
Share

Ok its working ;)

Thank you

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Raycast on sprite in 3D space, how to find texture coordinates 0 Answers

World scale of BoxCollider for Raycast and scale 1 Answer

How to rotate torso (sub mesh) of a model? 0 Answers

UI issue: Getting screen coordinates from a World Space object 1 Answer

Diagonal Raycast - Origin problem 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