Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 23, 2011 at 04:13 PM · rotationtransformpositionforwardsimplemove

how to ignore transform.position.y

In here I am trying to get the gameobject (dog) to come to its owners front (just like you would call a dog). I am trying to get it to ignore the players y position though. With this, the error is that the loop never breaks. When the function comeForward is called, it'll go the leaders front, but will trip out and never be still; it rapidly moves back and forth at the position.

If I just use transform.position instead of current position, it'll work, but will trip out just the same if on uneven terrain, hence my attempt to get it to ignore the y position of the leader.

 function Update(){
 
 var controller : CharacterController = GetComponent(CharacterController);
 var forward = transform.TransformDirection(Vector3.forward);
 moveDirection.y -= gravity * Time.deltaTime;
 
 //etc
 
 
 }if (comeHere){
 animation.CrossFade("walk");
 controller.SimpleMove(forward * speed);
 }
 
 }
 
 
 
 
 function ComeForward(){
 
 
 var currentPosition = transform.position;
     currentPosition.y = leader.position.y;
     while ( Vector3.Distance(  leader.position + leader.forward*3 , currentPosition ) >= .5) { 
 
         var lookPos = leader.position  - transform.position;
         lookPos.y = 0;
         var rotation = Quaternion.LookRotation(lookPos);
         transform.rotation = Quaternion.Slerp(transform.rotation, rotation, rotationSpeed); 
 
         comeHere = true;
         yield;
     }
 
     transform.LookAt(leader.position + leader.right * 5);
     animation.CrossFade("idle");
     comeHere = false;
 
    } 

 


What am I missing?

Comment
Add comment · Show 6
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 23, 2011 at 04:16 PM 0
Share

If you don't want to consider the vertical component why don't you just make Vector2s out of the x and z parts and compare distance with those?

avatar image superventure · Jun 23, 2011 at 04:19 PM 0
Share

An example please?

avatar image flaviusxvii · Jun 23, 2011 at 04:21 PM 1
Share

v3 is a Vector3

make v2 = new Vector2(v3.x, v3.z);

Now you have a position constrained to the xz plane, which i can compare against other positions on that place.. (Dog, Owner, whatever)

avatar image superventure · Jun 23, 2011 at 04:26 PM 0
Share

Is this for Js? It wouldn't allow that code, so I made it into var Vector2 = new Vector2(Vector3.x, Vector3.z); and it still gives me error messages. I will be back in a few hours- I have to go to work. Thanks so far

avatar image flaviusxvii · Jun 23, 2011 at 04:31 PM 0
Share

v3 is an instance of a Vector3, not the type Vector3. It wasn't any particular language. $$anonymous$$aking it work in JS should be trivial.

var xz_position:Vector2 = new Vector2(transform.position.x, transform.position.z);

Show more comments

3 Replies

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

Answer by superventure · Jun 24, 2011 at 04:18 AM

         var point2 : Vector3 = leader.position; 
         point2.y = transform.position.y;
         
         while (Vector3.Distance(point2 + leader.forward*3 ,  transform.position) > .5){
         
         transform.LookAt(point2 + leader.forward*3);
         
         comeHere = true;
     
         yield;
         
         }
         transform.LookAt(leader.position + leader.right * 5);
         animation.CrossFade("idle");
         comeHere = false;
         }
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 sneftel · Jun 23, 2011 at 04:16 PM

Your while loop is using a different goal position than your lookPos. So the gameobject moves towards leader.position until it gets to leader.position+leader.forward*3, which of course won't happen.

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 superventure · Jun 23, 2011 at 04:18 PM 0
Share

I tried to make both of them the same, but it still doesn't work. I also tried to take off '-transform.position' from look pos, and It made the dog veer off in one odd direction forever

avatar image sneftel · Jun 23, 2011 at 04:25 PM 0
Share

Nevertheless, once you fix that, the number of things you are doing wrong will have decreased by 1.

avatar image
0

Answer by Cymrix · Aug 02, 2011 at 05:26 AM

i was having a similar issue. i did not read all the posts here, but i ended up solving my issue by making my starting "y" value and my ending "y" value the tranform's "y" value.

 transform.position = Vector3.MoveTowards(Vector3(transform.position.x, transform.position.y, transform.position.z), Vector3(targetPoint.x, transform.position.y, targetPoint.z), speed);

transform.position = Vector3.MoveTowards(Vector3(transform.position.x, transform.position.y, transform.position.z), Vector3(targetPoint.x, transform.position.y, targetPoint.z), speed);

i separated the first vector3 to show/compare, but it's not needed, same thing could be done like this:

 transform.position = Vector3.MoveTowards(transform.position, Vector3(targetPoint.x, transform.position.y, targetPoint.z), speed);

i really wish you could just tell it to "ignore" a value, i've had mixed results with vector2, for some reason, though it seems it should be the same thing... well, i'm still noob level so maybe i'll figure it out someday.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

transform.forward doesn't work in my code 3 Answers

How to make a gameObject Transform Position move in a circle while making its Transform Position move forward? 1 Answer

Accurate placed object's transform messes up on game start 1 Answer

Stop moving at the target position by using Vector3.forward 0 Answers

Game Object won't match rotation of new positions transform 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