transform.position.y problem
i'm trying to create an AI algorithm for my bot but i believe that transform.position.x{get} works while transform.position .y is not. I've tried print the position as Vector3 and it's updating so that x but y is not. beside the first if statement it work it's fine while the second one doesn't.
if (randomCube.name.Equals("Cube (1,2)")) {
if (Mathf.Floor(transform.InverseTransformDirection(bot.transform.position).x) != Mathf.Floor(target.x) && !reach)
{
rigidbody.AddForce(moveDirection);
}
else
{
reach = true;
print(true);
bot.transform.position = new Vector3(target.x, 2.25f, target.z);
}
}
else if(randomCube.name.Equals("Cube (0,1)") || randomCube.name.Equals("Cube (0,3)"))
{
if (Mathf.Floor(bot.transform.position.y) != Mathf.Floor(target.y) && !reach)
{
print(bot.transform.position.y);
print(target.y);
rigidbody.AddForce(moveDirection);
}
else
{
reach = true;
print(true);
bot.transform.position = new Vector3(target.x, 2.25f, target.z);
}
}
Comment
Best Answer
Answer by DanSparrow · Feb 01, 2017 at 12:53 AM
Do you intend for it to move up? Remember Y in Unity is a vertical coordinate. Try z instead.
Your answer
Follow this Question
Related Questions
[Urgent] Finding Nearest Target 2 Answers
If two Vector2 are same 1 Answer
Player Floating 0 Answers
i need to change box position in y axis if i hit from down (c# script) 2d 1 Answer