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 Makenshi · Aug 10, 2010 at 11:02 PM · javascriptif-statementsvectors

vectors and ifs

Hi,everyone,what im trying to do is to have an object move back if 2 objects get close to each other and i have to do that with vectors but im getting an error. That error says Operator <= cannot be used with a left hand side of type 'UnityEngine.Vector3' and a right hand side of type 'UnityEngine.Vector3'

I seriously got no idea what to use so any idea would be really appreciated Thank You Very Much

function Update()
{
Player1= GameObject.FindWithTag("Player1");
Player2= GameObject.FindWithTag("Player2");
AllPlayers= Player1.transform.position + Player2.transform.position;
transform.position = AllPlayers/2;
if(AllPlayers <= Vector3(100,0,0))
{
transform.position.x=AllPlayers.x/2;
transform.position.y= AllPlayers.y*2;
transform.position.z=AllPlayers.z/2;
}
}

In case i wasnt really specific with my problem tell me plz i will try to explain it more

tried to do it this way and the other with alot of other things but seems like Transform wont let me do that it says the best overload for the method Distance is not compatible with the argument list UnityEngine.Transform The Problem is still in the same spot and this is how it looks like

var point1 : Transform; var point2 : Transform; var distance : float = 10; function Update () { if(Vector3.Distance(point1,point2)<=distance){ DoSomthing(); } }

function DoSomthing () { /*transform.position.x=(point1.transform.position.x + point2.transform.position.x)/2; transform.position.y= (point1.transform.position.y + point2.transform.position.y)2; transform.position.z=(point1.transform.position.z + point2.transform.position.z)/2;/ transform.position =(point1.transform.position+ point2.transform.position)/2; }

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

2 Replies

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

Answer by 3dDude · Aug 10, 2010 at 11:07 PM

you have to use Vector3.Distance(); for stuff like that EG :

var point1 : Transform; var point2 : Transform; var distance : float = 10; function Update () { if(Vector3.Distance(point1.position,point2.position)<=distance){ DoSomthing(); } }

function DoSomthing () { //do stuff here }

hope this helps

Comment
Add comment · Show 7 · 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 Makenshi · Aug 10, 2010 at 11:31 PM 0
Share

tried to do it this way and the other with alot of other things but seems like Transform wont let me do that it says the best overload for the method Distance is not compatible with the argument list UnityEngine.Transform

avatar image 3dDude · Aug 10, 2010 at 11:38 PM 0
Share

oh sorry :( here editing now

avatar image 3dDude · Aug 10, 2010 at 11:38 PM 0
Share

it should work know

avatar image Makenshi · Aug 10, 2010 at 11:41 PM 0
Share

ok thank you it works but is not doing what i want do u know a way for distance to add both of them? cuz its not doing it

avatar image Makenshi · Aug 10, 2010 at 11:48 PM 0
Share

never$$anonymous$$d srry i think it was my problem in the function thank you very much seriously!!

Show more comments
avatar image
0

Answer by cncguy · Aug 10, 2010 at 11:07 PM

You can't compare Vector3's that way as what does it actually mean for one to be less than the other?

What you actually want to do is compare distances

eg. Vector3.Distance(obj1, obj2) <= someDistance

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

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

1 Person is following this question.

avatar image

Related Questions

Why does if(levelToLoad ==null) not work? 2 Answers

If/else statements working one way, and not the other 0 Answers

Setting Scroll View Width GUILayout 1 Answer

Code not entering if statement. 1 Answer

(NOOB Q) Whats wrong with my script? Two if's? 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