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 Lemo76 · Feb 13, 2013 at 06:47 AM · guigameobjecttargetmaincamera

Moving Target Circle

Ok, this is going to be hard to explain without the visuals but I'l try. I started off wanting to have a GUI target picture in the middle of my screen (The target I use to aim my bullet at). Now I've decided I want something that is like the 2d circle which surrounds the cursor here:

http://www.youtube.com/watch?v=PqvjxHfU4PI

As you can see that as the cursor moves across the object, the circle rotates and moves around the object. How will I be able to have a target in my game which is like that when you look around? It would be very cool. I'm not so sure if I'm explaining it correctly. I hope you can understand and can figure out an answer.

Comment
Add comment · Show 2
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 AlucardJay · Feb 13, 2013 at 08:26 AM 0
Share

Here's a great answer by Aldo for finding the normal of a surface using a raycast. It then feeds information to a character controller, but the main parts are there. After watching the video I am interested and can help develop Aldos code for this purpose if you get really really stuck (or need a unity javascript version) =]

http://answers.unity3d.com/questions/168097/orient-vehicle-to-ground-normal.html

avatar image Lemo76 · Feb 13, 2013 at 08:17 PM 0
Share

Thanks that will be a very great help! How do I convert it into Javascript? This is how the gun works if you want to know what happens:

http://www.youtube.com/watch?v=1DtbFs7e2$$anonymous$$4

A stream of particles shoot out the gun which then hit a certain wall which sends a message to the wall stating it should instantiate a cube in the position of a null object.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by AlucardJay · Feb 18, 2013 at 08:27 AM

Try this :

 #pragma strict
 
 public var indicatorObject : Transform;
 
 private var currNormal : Vector3 = -Vector3.forward;
 
 function Update() 
 {
     var mouseRay : Ray = Camera.main.ScreenPointToRay( Vector3( Screen.width * 0.5, Screen.height * 0.5, 0.0 ) );
     
     var rayHit : RaycastHit;
     
     if ( Physics.Raycast( mouseRay, rayHit, 1000.0 ) )
     {
         // currNormal smoothly follow the terrain normal :
         currNormal = Vector3.Lerp( currNormal, rayHit.normal, 4.0 * Time.deltaTime );
         
         // calculate rotation to follow currNormal :
         var grndTilt : Quaternion = Quaternion.FromToRotation( -Vector3.forward, currNormal );
         
         // rotate indicatorObject
         indicatorObject.rotation = grndTilt;
     }
 }
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 Grug16 · Feb 13, 2013 at 07:13 AM

If you know what Raycasts are, it's fairly easy. Make a Plane with a transparent texture on it. Every frame, cast a ray from the mouse's position and set the plane's position to the hit.point and its rotation to hit.normal.

If you don't know much about Raycasts, definitely find some tutorials about them, as they are invaluable in 3D games.

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 Lemo76 · Feb 13, 2013 at 07:30 AM 0
Share

It is one hell of an annoying code. Can you show me a place with a code which will make doing this much easier. I've looked around and the codes I've found are either in C# or they just don't make any sense. This might be a big ask so I'm sorry.

avatar image Lemo76 · Feb 18, 2013 at 07:42 AM 0
Share

I eventually settled with this: http://www.youtube.com/watch?v=_UjSXAmXtJ4

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

11 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

Related Questions

GUI Window on GameObject location? 1 Answer

Find GameObjects and then add there name to an array? 0 Answers

Better to use Button or Touchable Gameobject? 1 Answer

Same BackGroung For All Screen Resolution 1 Answer

GameObject touchable instead GUI button 3 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