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

Just started using Construct 2? Post your questions here

Post » 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

Post » Mon Jun 27, 2016 1:37 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Dec 14, 2016 3:19 am

99Instances2Go wrote:https://www.youtube.com/watch?v=1nKgggGmEN8


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"...
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
79
S
12
G
7
Posts: 963
Reputation: 10,721

Post » Wed Dec 14, 2016 10:44 am

In addition to the answers, I want share something:
https://www.scirra.com/arcade/tutorial- ... pick-13549

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.
Image
B
107
S
24
G
17
Posts: 1,359
Reputation: 22,266

Post » Wed Dec 14, 2016 1:23 pm

pick object by UID
object.x object.y

thats all there is to it.
B
34
S
8
G
3
Posts: 169
Reputation: 3,305


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests