Making 2 Objects Attach?

Get help using Construct 2

Post » Wed Jul 03, 2013 7:03 pm

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


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
B
4
Posts: 9
Reputation: 743

Post » Thu Jul 04, 2013 12:46 am

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.
nimos1002013-07-04 00:53:50
B
44
S
11
G
2
Posts: 1,181
Reputation: 6,801

Post » Fri Jul 12, 2013 6:03 am

[QUOTE=nimos100] 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
[/QUOTE]

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:

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


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

[QUOTE=nimos100]
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
[/QUOTE]

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?
B
4
Posts: 9
Reputation: 743

Post » Fri Jul 12, 2013 6:18 am

[QUOTE=seancruz] [QUOTE=nimos100] I can see that, but I can't find any condition that checks distance.

[/QUOTE]
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.

Sushin2013-07-12 06:20:32
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Fri Jul 12, 2013 8:19 am

Ah okay, thank you very much Sushin! I need to become more acquainted with the functions.
B
4
Posts: 9
Reputation: 743


Return to How do I....?

Who is online

Users browsing this forum: bikachu, GabrielBalas, SoldjahBoy, Zaksoid and 12 guests