Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 superventure · Jun 24, 2011 at 02:28 AM · transformpositiondistanceforwardvertical

don't include vertical distance?

I have this code

 while(Vector3.Distance(player.postion + player.forward*3 , transform.position) > .5){
 transform.LookAt(player.postion + player.forward*3);
 //code to move forward
 yield;
 }

How do I properly tell it to ignore the players vertical distance? Thanks

Edit: a picture ref: I hope this makes things clearer, if not tell me. I will try again alt text

Comment
Add comment · Show 10
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 flaviusxvii · Jun 24, 2011 at 12:50 PM 1
Share

You've asked this question at least 3 different ways in the last three days. It's clear you have no idea what you are working with.

Please try some tutorials and get a feel for vector mathematics and 3d spaces. This sort of exhaustive guided debugging is NOT what Unity Answers is for.

avatar image superventure · Jun 24, 2011 at 11:57 PM 2
Share

It's not that I have no idea what I'm working with, it's that I'm confused. I know of the manuals and general tutorials. If I could figure it out on my own, I wouldn't be putting up with the trouble so many times. I need an ANSWER. Hence, I come to Unity...Answers. It's not like I'm asking for free codes. If this site is not for guidance and 'debugging', then what it is for?

avatar image flaviusxvii · Jun 25, 2011 at 12:38 AM 0
Share

We're all confused too. Apparently you're not conveying your problem in a clear manner. I'll tell you what. You draw a picture of your general problem. Forget dogs and people. Just break it down to the fundamental issue. Drop any "solutions" you're trying to make work. Just give us what you have to work with and what you want to get out of it. I want to devote as much time to this as I possibly can to get it answered and off of the site **forevar!!!!!*

avatar image superventure · Jun 25, 2011 at 02:13 AM 0
Share

Okay, I will post an example in my question

avatar image flaviusxvii · Jun 25, 2011 at 03:22 AM 0
Share

Ok, lots of people here are giving you stellar answers from what I can tell. It seems the problem is that you are plugging this into a larger script and you're not seeing what you expect, because some other part is broken.

Reduce it to the simplest case so you know what we are telling you works. This is a trivial problem. Constraining a distance measurement to the X-Z plane.

Something else must be wrong.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by testure · Jun 24, 2011 at 04:33 AM

just create a new vector that uses the object's y position rather than the player's:

Vector3 temp = new Vector3(player.position.x, transform.position.y, player.position.z)

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 superventure · Jun 24, 2011 at 05:41 AM 0
Share

Transform.LookAt is still ai$$anonymous$$g for the y vector though, on uneven surfaces, even if it's in the correct xz postion to the player, it still aims for the y of the player. What now?

avatar image testure · Jun 24, 2011 at 05:49 AM 0
Share

your code is telling it to look at the player's position and adding a local forward * 3 to it. both player.position and player.forward contain this "Y" value that you want to ignore, you're going to have to zero them both out, otherwise you're just adding it back in.

avatar image superventure · Jun 24, 2011 at 06:09 AM 0
Share

Okay, the closest I got to that was this, but it still doesn't work. What did I do wrong?

 var point2 : Vector3 = leader.forward; 
     point2.y =  transform.forward.y;
     var Vector3 = new Vector3(leader.position.x, transform.position.y, leader.position.z);

     while (Vector3.Distance(leader.position + point2*3 ,  transform.position ) > .5){
     
     transform.LookAt(leader.position + point2*3);
avatar image testure · Jun 24, 2011 at 06:47 AM 0
Share

What is var Vector3 defining? I don't use JavaScript, but don't you have to supply a variable name? It looks like you're using a type as a variable name. Additionally, leader.position still has the y you're tring to get rid of.. It gets added back in every time.

avatar image superventure · Jun 24, 2011 at 07:00 AM 0
Share

okay, how about this one (still malfunctioning)

 var point1 = leader.forward; 
     point1.y = transform.forward.y;
     
     var point2 : Vector3 = leader.position; 
     point2.y = transform.position.y;
     
     while (Vector3.Distance(point2 + point1*3 ,  transform.position) > .5){
     
     transform.LookAt(point2 + point1 *3);
     
     comeHere = true;
     yield;
     }
     transform.LookAt(leader.position + leader.right * 5);
     animation.CrossFade("idle");
     comeHere = false;
     }
Show more comments
avatar image
0

Answer by Joshua · Jun 25, 2011 at 12:32 AM

The easiest way to get the distance between two vectors if you want to ignore height (or an other dimension) is

 var a : Vector3;
 var b : Vector3;
 function Start() 
 {
     print( "ignoring height, the distance between a and b is " 
                          Vector3( a.x-b.x, 0, a.z-b.z ).magnitude );
 }

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 aldonaletto · Jun 25, 2011 at 12:45 AM 0
Share

You've forgot something:

Vector3(a.x-b.x, 0, a.z-b.z).magnitude

avatar image Joshua · Jun 25, 2011 at 02:15 AM 0
Share

ouch, you're right. What's with me today...

avatar image superventure · Jun 25, 2011 at 02:16 AM 0
Share

will try this out brb...

avatar image superventure · Jun 25, 2011 at 02:39 AM 0
Share

does this calculate x and z distance the same as my last attempt? It acts the same way as before. You're right with your example, but I think the distance part isn't the issue though, I think it's how I have LookAt set up. The object will go the right position but once there, will rapidly move around at in that spot. I think I somehow am STILL adding height to that somewhere?

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

7 People are following this question.

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

Related Questions

Distance won't work 1 Answer

Set position to transform.forward+distance 0 Answers

distance to variable object 1 Answer

Moving child and parent 1 Answer

how do i fix my script in the content below? 0 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