How do I have an objects position always between two others

0 favourites
  • 6 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I have two objects that move and I have another object that I would like to stay in the horizontal and vertical middle of both objects. Lets call the to moving objects leftPlayer and rightPlayer and the middle object spr_middle. I made global variables that sets itself to the horizontal distance and vertical distance between leftPlayer and rightPlayer every tick.

    Suppose that the screenWidth is 1000, leftPlayer.X is 250 and rightPlayer is 750. spr_middle should be at 500. Every tick this should adjust itself depending on how leftPlayer and rightPlayer move. After I figure that out I could do the same for the height and the Y axis...

    Thanks for any help...this has been driving me crazy...

  • inbetweenx=(ax+bx)/2

    inbetweeny=(ay+by)/2

  • bizzy401

    Maybe something like this, you can drag the objects and see

    Capx: https://www.dropbox.com/s/3v44fg3tf35ihs3/TheMiddle_Object.capx?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • https:// drive.google.com/open?id=0Bzy8n1DGExZvOEVidGRXLUc0WHc <---remove the space after the https://

    Here is what I am working on, both methods that were proposed work, but if the leftPlayer and the rightPlayer switch sides it ceases to work properly. I think I may have to make four different "if" statements depending which sides them players are at to get it to =work right

    Thanks for all of the help.

    The game has to be controlled with a controller for the record...

  • Doesn't this do what you want: cameraBox:Set position: (rightPlayer.X+leftPlayer.X)/2, 360

  • https:// drive.google.com/open?id=0Bzy8n1DGExZvOEVidGRXLUc0WHc <---remove the space after the https://

    Here is what I am working on, both methods that were proposed work, but if the leftPlayer and the rightPlayer switch sides it ceases to work properly. I think I may have to make four different "if" statements depending which sides them players are at to get it to =work right

    Thanks for all of the help.

    The game has to be controlled with a controller for the record...

    Hi,

    When you say if the switch sides ceases to work properly what you mean with that can you be more specific, because is working here on my side in the capx I provided you, if I didn't understand wrong the goal was to center the middle object in the center between left object and right object at every thick, is that correct?

    if not can you explain more what you trying to accomplish will be easier for someone to give you the right help

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