I having a problem where my 2D objects seem to moving on an arbituary Z axis.Not sure why this started happening but I thought it was a result of me switching to a more physics based movement because I was modifying the transform.position before. I started playing around with the Rigidbody2D.position and realized the Z axis was getting changed which didn’t make sense since I was working with a Vector2 but anyways I took on unethical means to try and keep the Z axis on a positive number by using " transform.position = new Vector3(transform.position.x,transform.position.y,0) " but this didn’t work and I saw this is not a good practice. Out of frustration I switched back to modifying the transform.position but the problem still persist so I don’t know what to do.
It’s 2D physics, it doesn’t touch the Z position because that would be 3D physics. You must be setting it somewhere or have some animation doing it.
Thanks for the response. I figured it out I hope. I went back in the documentation to see if it could help and I saw where my problem was. At the start of my game I would use transform. Position to set a start position and then the Rigidbody2D. Position to move the object. I fixed my problem by just abandoning any use of transform. Position in terms of object movement and placement.But unfortunately switching to this. Brought forth another problem. I not sure but is there other way to use Rigidbody2D. position in code , not sure if it makes sense but I had to ask. The reason I asked was because before if I used transform.position and make it equal to a Vector3 outside of any update or IEnumeration it would do it instantly. But for some reason setting Rigidbody2D. position to a new Vector2 while its being updated in the Fixed Update at the same time doesn’t do nothing. Should I use a boolean to stop the Fixed update process to then execute the line of code then after thats done allow the Rigidbody2D. Position to be updated once again?
I’m not following what you’re asking nor why you would think the Rigidbody2D has any relation to the Z position changing as it doesn’t touch it.
This is a double-negative but if you’re saying that setting the Rigidbody2D.position doesn’t instantly set the Transform.position then that’s correct.They are separate things. A Rigidbody2D will write its pose to the Transform at the end of the simulation as always.
Likewise, setting the Transform.position only changes the Transform.position, it doesn’t change any other component in Unity. Even renderers only use it when they render. When a Rigidbody2D is first created (before it is activate) it uses the current Transform position as its start. This means it’ll be correct so if you’re instantating something with a Rigidbody2D using Instantiate then specify the position/rotate in the Instantiate call; don’t change the Transform after.
Rather than speculating on stuff though, I’d recommend you ask a concise/direct question here, then maybe I can answer that. Also post some code.
Sorry for my lack of transparency in my question, but I found a solution the problem I was having.What I was asking was is there a proper way to move an object from point A to B instantly using Rigidbody2D.position using a line code/s in a Normal Method not the Update Method since there seems to be a delay in the time it takes to update the objects transform? I found a way to wait for the Physics simulation to finish but It requires me to still use the Update Function.I am not to verse on the whole UI of the Unity forum so I don’t really know how to send code but I can send screenshots.
The above is entirely unnecessary but I still don’t understand what you’re actually doing. I think you don’t yet have an understanding of when things run and seem to be a little fixated on the synchronisation between Rigidbody2D/Transform; just not sure what problem this is causing you.
You are also free, depending on your project/game type, to simply set the physics to run per-frame in which case, the simulation is run per-frame and the Rigidbody2D will therefore write to the Transform per-frame.
I’m not going to describe all that though, there’s plenty of material online about this.

