0 Favourites

Making 2 Objects Attach?

  • Hello,

    In my prototype, the player can dig/mine tiles. I want the player to have several options as to how he/she can go about mining. If you double left-click a tile, the spaceship heads towards the tile, but it won't face the tile or mine it.

    I envision the spaceship attaching to the tile once it arrives at a certain distance, and starts to mine the tile until destroyed.

    Right now, if you double click a tile, the spaceship will fly towards the tile, but it won't face the tile. How can I get the spaceship to collide or touch the tile from the front tip of the ship?

    Here's my CAPX to see: CAPX

    <font color="green">Controls:

    You can move via:

    -WASD or Arrow Keys

    -or, click anywhere in space to move

    -or, double click a tile to move towards it

    -Fly faster by holding SHIFT

    You can mine by:

    -Facing and touching the tile, and holding down SPACE</font>

  • You just need to check the distance between the tile and spaceship.

    So if distance(Spaceship.X,Spaceship.Y,Tile.X,Tile.Y) <= 100

    Spaceship.stop (The pathfinding one)

    Spaceship.set angle towards position tile.x,tile.y

    The spaceship wont collide with the tiles as they are solid. However you can turn off solid for the selected tile if you want, but you have to regenerate the obstacle map then. And in its current state if you have to many objects, your program might pause for a short time while calculating, which makes the function rather useless, as no one cares to play a game that pauses all the time :D

    Also you don't have to use a "dummy" object (The red square) for you player craft. You just have to make sure that the spaceship is flying the correct way in the image. that being to the right, Like this:

    Back of spaceship >----O> Front of spaceship

    Furthermore I can see you have scaled your spaceship, its better to make it the correct size from start, as it will otherwise use more memory than needed. It might not be a problem now, but later on you might run into some performance problems. It can be done quite easily if you use the image editor in C2.

    To do it correctly, you have to do the following.

    1. Rotate all the animations 90 degree CW, so they point right.

    2. For each animation scale them to the desired size and exit the editor.

    3. Select you spaceship Then you can see the "angle indicator" in the middle of the sprite points in the direction of the front of your spaceship.

    4. On the spaceship, you have to set the "size" to what you made it in the editor as well, as it still scales it, with the same amount as before you scaled them in the editor.

  • You just need to check the distance between the tile and spaceship.

    So if distance(Spaceship.X,Spaceship.Y,Tile.X,Tile.Y) <= 100

    Spaceship.stop (The pathfinding one)

    Spaceship.set angle towards position tile.x,tile.y

    Hi nimos100, thanks for taking the time to answer, and for the suggestions.

    Unfortunately, I can't figure out how to check the distance in C2. I understand you when you said to check the distance via:

    <font color=brown>if distance(Spaceship.X,Spaceship.Y,Tile.X,Tile.Y) <= 100

    Spaceship.stop (The pathfinding one)

    Spaceship.set angle towards position tile.x,tile.y</font>

    I can see that, but I can't find any condition that checks distance.

    The spaceship wont collide with the tiles as they are solid. However you can turn off solid for the selected tile if you want, but you have to regenerate the obstacle map then. And in its current state if you have to many objects, your program might pause for a short time while calculating, which makes the function rather useless, as no one cares to play a game that pauses all the time :D

    Let's say you open the game on the iPad. You touch-click on an asteroid tile, and the spaceship flies over to the tile, is angled towards the tile, and mines the tile on its own. All through just one touch on a tile. Is that possible without having to turn off collision?

    Or what if, you flew the spaceship by pressing and holding your finger down on a tile, and the spaceship follows the position of your touch, thereby making the ship mine the tile?

  • > I can see that, but I can't find any condition that checks distance.

    >

    >

    There is a built in function you can call simply called "distance"

    Just type "distance" into the prompt and it will appear. Type your values in the parenthesis and it will return a value equal to the distance between the two objects.

    <img src="http://puu.sh/3ATyq.png" border="0" />

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Ah okay, thank you very much Sushin! I need to become more acquainted with the functions.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
167 14,484
DMT2005's avatar
DMT2005
Unread sticky
1 Favourites
C2 Games made with CocoonIO
136 89,806
minhcuong's avatar
minhcuong
Unread hot topic Locked topic
83 19,079
Kyatric's avatar
Kyatric Construct Team Support