Need to update position from a Json file

I’m working on a project for school, I couldn’t figure out how to build the thing using primitives in C#, so I asked my professor and he said I could use Unity instead. I’m using the first project in the 2D unity course as inspiration, but the way I need to move my car is by position according to a JSON file updating from Firebase. Essentially, there are 4 sensors, and we have bluetooth beacons that represent the cars. The Json file is going to tell us how far away each car is from the 4 sensors and we triangulate it’s position. I already have the algorithm for triangulation of position, what I need is to figure out how to get Unity move the car based on that position on Update, rather than using transform.translate.

How do I update position?

Hi James,

You could override transform.position of the game object whose position you want to change. Unity does not care where the value comes from as long as it has the correct data type.


See also:

There seems to be nothing different here. You say you already have the algorithm to triangulate the position, now you just need to move the car. This is the same as moving anything in Unity. The json has nothing to do with this.

When you have a target position, you just point the car to the position and move it forward

// In the car's update - assume target is a Vector3
var direction = (target - transform.position).normalized;
transform.forward = direction;
transform.Translate(Vector3.forward * speed * Time.deltaTime);

Edit
If you just want to set the position, just set it. Like @Nina said;

// In the car's update - assume target is a Vector3
transform.position = target;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms