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 lampshade · Jun 15, 2010 at 11:42 PM · overlapsphere

Outside of OverlapSphere

Hi,

The Problem is still Buggy: When the player is outside of the radius, when the Player stops, turns around (or move backwards), and then proceeds toward the radius, my varaible still decrements! Bad. If I am outside of the radius, and proceed closer to the radius, I need to be incrementing...

I set up the below Vector3.Distance with if else blocks because I think it works more to my expectations than overlap sphere!

Vector3 lastPosition, oldPosition; Vector3 vecToTarget = GameObject.Find("Object1").transform.position - lastPosition;

 if (Vector3.Dot(lastPosition.normalized, vecToTarget.normalized) > 0)
 {
     if (! pause_variable && variable <= 1)
     {
         //incrememnt varaible
     }
 }
 else
 {
     if (! pause_variable && variable > 0)
     {
         //increment variable
     }

     if (Vector3.Distance(oldPosition, transform.position) < 0.90f)
     {
         pause_variable = true;
     }

     if (Vector3.Distance(oldPosition, transform.position) > 0.90f)
     {
         pause_variable = false;
     }

 }

 oldPosition = transform.position;

 lastPosition = transform.position;

What I mean by buggy, is that when the player moves away from the object, rotates 180 degrees, then moves back toward the object, the varaible decrements.....when it should increment. I have tested this thoroughly and what I am telling is what unfortunately happens.

It would also be nice, if I could somehow use the radius like in OverlapSphere, that way I don't have to get incredibly close to the object for my varaible to increment.

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 Tetrad · Jun 15, 2010 at 11:44 PM 0
Share

Not that this helps you at all, but it's spelled "variable".

1 Reply

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

Answer by Tetrad · Jun 15, 2010 at 11:51 PM

The problem with your logic and your desired results doesn't seem to be the overlap sphere bit, but you need the logic for "am I moving towards the sphere".

For that there's an easy solution.

Assuming you have the forward vector of the player's movement, you can do something like this.

Vector3 vecToTarget = GameObject.Find("Object_1").transform.position - player.transform.position;

if( Vector3.Dot( player.movement.forward.normalized, vecToTarget.normalized ) > 0 ) { // player is moving towards the target } else { // player is moving away from the target }

Although not Unity documentation, a good resource on the dot product can be found here: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.vector3.dot.aspx

Comment
Add comment · Show 9 · 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 lampshade · Jun 15, 2010 at 11:54 PM 0
Share

Thanks, for the response, I'll try it out..

avatar image lampshade · Jun 16, 2010 at 02:25 AM 0
Share

That's still buggy, codes shorter though :x

avatar image Tetrad · Jun 16, 2010 at 04:04 AM 0
Share

Buggy how? What do you need to happen exactly? What are the results you're expecting? What results are you seeing?

The only thing I can think of that might be an issue for the "increment if you're moving towards, decrement if you're moving away" is that you might have to special case the player not moving case.

avatar image lampshade · Jun 16, 2010 at 05:02 AM 0
Share

The above "snippet" is a script attached to the player. So transform.position is a position that I control

avatar image Tetrad · Jun 16, 2010 at 05:03 AM 0
Share

You don't want to do the dot product with the last position, you want to do the dot product with the player's forward velocity vector.

Show more comments

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

No one has followed this question yet.

Related Questions

Local Gravity (Black Hole) 1 Answer

How can I access collider's game objects? 1 Answer

How to get an array of transforms and move GameObject for certain duration to that transforms list 0 Answers

Preventing Spawn Overlap With Spheres 1 Answer

OverlapSphere seems to detect everything and ignores tags. How can I fix this? 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