|
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. What am I missing?
(comments are locked)
|
(comments are locked)
|
|
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. 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
Jun 23 '11 at 04:18 PM
superventure
Nevertheless, once you fix that, the number of things you are doing wrong will have decreased by 1.
Jun 23 '11 at 04:25 PM
sneftel
(comments are locked)
|
|
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); i separated the first vector3 to show/compare, but it's not needed, same thing could be done like this: 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.
(comments are locked)
|

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?
An example please?
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)
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
v3 is an instance of a Vector3, not the type Vector3. It wasn't any particular language. Making it work in JS should be trivial.
var xz_position:Vector2 = new Vector2(transform.position.x, transform.position.z);