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

0 favourites
  • 5 posts
From the Asset Store
Act on your instances, get/set their properties and variables only thanks to their UID. No more picking trouble! Plugin
  • 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!

  • Subscribe to Construct videos now
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • youtube.com/watch

    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"...

  • 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.

  • pick object by UID

    object.x object.y

    thats all there is to it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)