- Home /
position.Set does not working on rigidbody2d
I have a gameobject:

I've attached to it a rigidbody2D, and in my code I am trying to change its position, but when I run the game nothing happens.
void Update()
{
float Hip_Center_X = sw.bonePos[0, (int)Bones.HipCenter].x;
rigidbody2D.transform.position.Set(10, 2, 0);
if (sw.pollSkeleton())
{
if (Hip_Center_X > 0.25)
{
anim.SetInteger("direction", (int)Direction.right_idle);
}
else if (Hip_Center_X < -0.25)
{
anim.SetInteger("direction", (int)Direction.left_idle);
}
else if (Hip_Center_X < 0.25 && Hip_Center_X > -0.25)
{
anim.SetInteger("direction", (int)Direction.up_idle);
}
print(sw.bonePos[0, (int)Bones.HandRight].y);
}
}
What I am missing?
player.png
(54.9 kB)
Comment
Answer by gtotoy · Mar 21, 2014 at 04:02 PM
Hi, transform.position is returning a copy of position (Vector3 type) and you are setting (10, 2, 0) to the copy. You should change rigidbody2D.transform.position.Set(10, 2, 0); to rigidbody2D.transform.position = new Vector3(10, 2, 0);
Your answer