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 sam32x · Aug 24, 2012 at 08:14 AM · objectscreenbumpmapsomething

moving an object when the character is not looking

i have an object and i want to put a heap of empty gameobjects with tags in my scene and the position of the object will be the closest one of those empty gameobjects, also i dont want it to be able to move when it is on the screen. how would i do this? also does anyone know how to put a bump map on a terrain texture?

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
Best Answer

Answer by Toby-Grierson · Aug 24, 2012 at 01:37 PM

One question at a time! I'll tackle the moving object.

I'm reading your question like so; you have object A, camera C and set of empties S.

When object A is not visible to camera C, you want to to move to the empty in set S which is closest to either the camera C (or character B).

Yessir? I'll answer.

So you need a component which you can add to object A which will move it. Let's call this MoveWhileHidden.

 class MoveWhileHidden: MonoBehaviour
 {
 public Transform[] positions; //Use the inspect to add all the empties.
 public Transform theChased; //We want to be close to this thing.
 
 bool mayMove = false;
 
  void OnBecameInvisible() {
   mayMove = true;
  }
 
  void OnBecameVisible() {
   mayMove = false;
  }
 
  //This may return null.
  Transform findNearest()
  {
   Transform nearest = null;
   float nearestDistance = float.MaxValue;
   foreach(Transform t in positions)
   {
    float f = (t.position - theChased.position).sqrMagnitude;
    if(f < nearestDistance)
    {
     nearestDistance = f;
     nearest = t;
    }
    return t;
  }
 
  void Update()
  {
   if(mayMove)
   {
    Transform t = findNearest();
    if(t != null)
    {
     transform.position = t.position;
    }
   }
 }

Make sure to put the empties in there. You might also use a GameObject.Find[...] method with a tag to populate the list at runtime.

Please ask about the bump mapping in another thread.

Comment
Add comment · Show 4 · 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 jheiling · Aug 27, 2012 at 01:26 PM 0
Share

$$anonymous$$ay I recommend starting and stopping a coroutine ins$$anonymous$$d of using may$$anonymous$$ove and Update. Then you could use a time interval ins$$anonymous$$d of updating every frame, which might be a bit too often.

avatar image Toby-Grierson · Aug 27, 2012 at 01:39 PM 0
Share

There's a good idea. One must only take care to stop it correctly though because if the decision point is too far decoupled from the game's operation, it may accidentally move when it's in view. The cost is only O(n) with the number of potential points, so whether or not any effort to optimize is warranted does depend on platform target and if there's a few points or a few hundred.

avatar image jheiling · Aug 27, 2012 at 02:23 PM 0
Share

Sure, it's not that important really (it must be my age, back then when I was young... ;) ), but there is no problem if you start / stop the coroutine where you set may$$anonymous$$ove now. You don't have to do any extra checks, because the coroutine is not running when the enemy is visible.

avatar image Toby-Grierson · Aug 27, 2012 at 02:26 PM 0
Share

Sure that makes sense.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

l want my game object to appear in a location and change when screen size changes? 0 Answers

how to scale an object in order to fix the screen dimensions 3 Answers

how do i put a bumpmap on a terrain texture 1 Answer

How do you find an object in the middle of the screen? 1 Answer

How to detect if object has left the screen? 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