0
Answered

Shooting a Cannonball?

rholzem 4 months ago in Game Creator updated by Marti (Lead Developer) 3 months ago 3

Hello, 

how can I set the firing trigger for the cannon?

Unity version:
2019.2.13f1
Game Creator version:
1.1.2

Answer

Answer
Answered

Hi;

You are almost there! The Instantiate Action creates an instance of the "Cannon Ball" and you want to apply a force impulse to that, right?

First you need to have a reference to the instantiated "Cannon Ball". To do that, create a Local Variable below the Action of type "Game Object" and call it, for example "cannon-ball".

Then, under the Instantiate Action, where it says "Store (optional)", select Local Variable and drop in the "projectile" scene game object. Then, select the "cannon-ball" variable from the dropdown list.

Now you have a reference to the instantiated cannon ball. All that's left to do is apply force to this game object. To do it, using the Physics Action you have, change the "Target" field to "Local Variable". Repeat the same process as before: Drop in the "projectiles" game object and select the "cannon-ball" from the dropdown list.


That's is! Click play and click on the little "play button" at the bottom-right corner of the Action. This will allow you to debug this mechanic.


Hope this helps!

Answer
Answered

Hi;

You are almost there! The Instantiate Action creates an instance of the "Cannon Ball" and you want to apply a force impulse to that, right?

First you need to have a reference to the instantiated "Cannon Ball". To do that, create a Local Variable below the Action of type "Game Object" and call it, for example "cannon-ball".

Then, under the Instantiate Action, where it says "Store (optional)", select Local Variable and drop in the "projectile" scene game object. Then, select the "cannon-ball" variable from the dropdown list.

Now you have a reference to the instantiated cannon ball. All that's left to do is apply force to this game object. To do it, using the Physics Action you have, change the "Target" field to "Local Variable". Repeat the same process as before: Drop in the "projectiles" game object and select the "cannon-ball" from the dropdown list.


That's is! Click play and click on the little "play button" at the bottom-right corner of the Action. This will allow you to debug this mechanic.


Hope this helps!

Hi Marti, 

I tried to do what you have written, however i'm stuck on the store optional part it doesnt let me drag in the cannon-ball variable

Hi Rholzem;

I'm assuming "projectile" is the canon object that is shooting instances of "Bomb_Shot" objects. Correct? In that case, you almost have it.

The "Store (Optional)" field allows to temporally store a reference to the "Bomb_Shot" scene instance instantiated from the prefab.

To use it, simply add a Local Variable component at the "projectile" game object, below the Actions, and create a new variable called "instance" (for example). Select the "Game Object" as the type of the variable.

Now, under the "Store (Optional)" field of the "Instantiate" Action, exactly at the image you posted above, drop in the "projectile" game object instead of the "Bomb_Shot". If you click the dropdown menu, it should appear the "instance" variable you just created. Select it.


From now on, when you instantiate a "Bomb_Shot" prefab, the "instance" variable will contain a reference to that scene instance, which you can use to apply force, destroy it, change its color or whatever you desire.


Hope this helps!