How do I make an object match position?

0 favourites
  • 15 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Not a very clear title...

    I have an object that I want to move using the arrow keys. Up down left right.

    Now, I also want to have a copy of the exact same object copy its movement exactly, but its Y position at a +200 offset.

    I've set up a boolean which separates them, so the arrow keys only effect the correct one, but how do I add in some code that gets an object to follow itself, but with a different boolean?

    I could do it easily with a different object, but I'm trying to cut down on my use of sprites.

  • Pin at offset?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm, I guess that could work. I'd need to have the object spawn itself, offset it's Y position, change the boolean, then pin.

    Nice, this could be a winner!

    This the only way to do it? Wish I could add extra parameters to these things so I can more easily reference them. Say for example I only want the object to follow on the x access, not both.

  • Nope, can't get pinning to work. It just tries to pin itself to itself, rather than the original. You can only choose the object from a list, rather than code it in and add a UID to the end

  • Choose by instance 0, and 1. But when you Pin, it will 'follow 'on both axes'. Otherwise you need to do it yourself, every tick. That would be very simple.

  • I'm afraid I do not follow. If I have a choose by UID 1 (which is the copy) I will then need to tell it which one to pin to... but when I add a choose by UID 0 (The original) I can't separate this, as the two will read "Choose by 0 AND Choose by 1". I've never needed to do this, so never learned this part I'm embarrassed to say!

  • No that's fine, Use IID not UID. i.e. pick by Nth

    Edit: how much are you going to save by using the same object type? Maybe just use different objects and save a lot of work.

    Anyway I've attached something that might help.

  • I've also tried doing it using the expressions within the Parameters for X, but not having any luck with that either.

  • I've also tried doing it using the expressions within the Parameters for X, but not having any luck with that either.

    Sorry if I was a bit cryptic. Anyway see above ^^ Hope it helps.

    Edit: I had some errors and uploaded a new capx. Sorry for multiple uploads.

  • Thanks a lot! I appreciate the help, but I do not believe this method will work.

    My game has 4 ships that I need to do this with, and all are already part of a family. I have tried to alter your code to allow a second sprite to be linked in via the same family, but it does not work.

    I will go with your initial advice, and just use separate objects. I was trying to avoid this, as my debugger is slowly turning into a nightmare, filled with objects. Sadly, groups do not transition over, so I need to scroll through dozens of objects just to find the one I'm looking for!

    I greatly appreciate your help though!

  • Thanks a lot! I appreciate the help, but I do not believe this method will work.

    My game has 4 ships that I need to do this with, and all are already part of a family. I have tried to alter your code to allow a second sprite to be linked in via the same family, but it does not work.

    I will go with your initial advice, and just use separate objects. I was trying to avoid this, as my debugger is slowly turning into a nightmare, filled with objects. Sadly, groups do not transition over, so I need to scroll through dozens of objects just to find the one I'm looking for!

    I greatly appreciate your help though!

    Did you try the last uploaded version? It has 4 sprites. And just create another family for the picking purpose. But yeah.. unless you're going to save heaps of memory.. use separate object types.

  • Yeah, figured I'd need a new family. I currently have 21 and counting (very large game), so I'm trying to keep it down. Oh well!

    Thanks so much for the help!

  • Yeah, figured I'd need a new family. I currently have 21 and counting (very large game), so I'm trying to keep it down. Oh well!

    Thanks so much for the help!

    No worries. And yea you're right, it won't work.. easily

  • AnD4D

    Are the objects created and destroyed at runtime?

    You could do this if the first 4 instances are controllable and the last 4 are ghost.

    Sprite Boolean "ghost" is set

    --- sprite set x to sprite(sprite.iid-4).x+400

    Or if you just want each instance with ghost set to be at an offset you could do

    Global otherx=0

    Repeat 4 times

    ---Sprite is ghost

    ---pick sprite instance loopindex

    ------set otherx to sprite.x

    ---sprite is not ghost

    ---pick sprite instance loopindex

    ------sprite set x to otherx+400

    Of course with that example there are 8 instances.

  • R0J0hound - Ahh, this "set x to sprite(sprite.iid-4).x+400" is what I've been looking for!

    Thanks!

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