# How do I get an object's position from its UID?

Just started using Construct 2? Post your questions here

### » Mon Jun 27, 2016 8:39 am

I want to make a GTA-like game and have people getting in and out of cars (plural). But the problem is that when I make a second car that is the same object as the first one my player follows the first one. The second car works fine as in drivability, camera control, ect.

My idea is to write down the Unique ID of the car the player is entering on a global variable and then set it so it follows a global variable that every tick says where the position of the car with (let's say) UID 12 is.

My problem is that i don't know if its possible or how to do the part highlighted in orange.
I would greatly appreciate if someone were to help me!
B
4
Posts: 11
Reputation: 202

### » Mon Jun 27, 2016 1:37 pm

B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Wed Dec 14, 2016 3:19 am

Is that your video? It doesn't answer the question even slightly! Why on Earth would you link someone to that?

The question was how do you get the X and Y position of an object based on an object's UID. The video just shows an event that says "If A collides with B, destroy UID 3"...
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758

### » Wed Dec 14, 2016 10:44 am

In this example with sample CAPX you'll be able to learn how to deal with UID and how to pick it, also, how to filter conditions using it and achieve anything you want to manipulate the desired object.

For example, you want the player picking the right car? Simple, on collision with this car (trigger, not a permanent checking) set it's UID to the Global variable.

Now you're able to pick this car by filtering it in the condition.
Condition: Pick by Evaluate -> Car with Car.UID = GlobalVariableCar

So, you want its X and Y to update the player position inside the car? Improve with.

Condition: Pick by Evaluate -> Car with Car.UID = GlobalVariableCar

Action: Pin Player to Car;
(it will pin the player to the car, better than using resource with updating every tick, who will consume your CPU more than pin, also, pin have priority over updating position)

or

Action: Set Player Position to Car.X,Car.Y;
(Don't worry, when you filtered the car UID, it's dealing only with him, but avoid update something everytick, use pin instead, it's more efficient)

That's it.
B
110
S
24
G
18
Posts: 1,391
Reputation: 23,017

### » Wed Dec 14, 2016 1:23 pm

pick object by UID
object.x object.y

thats all there is to it.
B
40
S
11
G
5
Posts: 180
Reputation: 4,777