circus cannon

  • Hi,

    I'm trying to do a simple circus cannon example, where the cannon object constantly rotates from it's pivot (positioned opposite the barrel opening) and upon mouse down/touch, it fires.

    The Sine behaviour is close to what I want, but I can't seem to control the right angle limits of the cannon.

    Any ideas?

    (image explaining concept below)

    http://imgur.com/vYaoiqb

    Thanks.

  • Just found the perfect behaviour to do this, compliments of RexRainbow. It's called swing, and can be found here:

    http://www.scirra.com/forum/behavior-swing_topic46029.html

    Thank you.

    My question is: how can this be emulated in the event sheet without that behaviour?

    Cheers.

  • Hi Flaye,

    I have a solution to your cannon problem.

    LIVE

    drappdev.net46.net/Construct2/MySolutions/topic68707

    Capx

    drappdev.net46.net/Construct2/MySolutions/topic68707_solution.capx

    Uses 2 events to check the angle and change the 'direction' speed from 30 to -30.

    Hope this helps.

    DR App Dev

  • Thank you, drappdev! That works well.

    I guess I was trying to overcomplicate things with variables and loops.

    My thought process was as follows:

    1. Set a starting and end angle variables.

    2. Create a loop that will rotate the cannon from start to end value.If end value is reached, rotate from end to start.

    3. Continue until LMB/touch are pressed. Find stopped angle

    4. Stop rotation of cannon. Play fire animation and shoot projectile at stopped angle value.

    I come from 3D background and do a lot of animation scripting. Sometimes the simple elegance of C2 requires to slow down and smell the roses :)

    So based on your example, the values that are being sent to the text object can then be used to set the projectile angle of the fired object.

    I'm assuming I should use a bullet object with physics, since I want a parabolic arc.

    The point of the game is to keep the fired object afloat as long as possible.

    I'm trying to get mechanics similar to this:

    Subscribe to Construct videos now

    Thanks.

  • I'm assuming I should use a bullet object with physics, since I want a parabolic arc.

    I am new to C2 - if I wanted to fire a bullet from the canon I would, as you mention use the bullet & physics behaviour together.

    Good luck, hope your game develops well

    DR App Dev

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • drappdev - quick question..

    What did you set the FLOOR variable to? I'm trying to rebuild as per your example, but I can't find the connection of it to the cannon sprite.

    Thanks.

    [edit]

    Nevermind. Floor is a math function.

  • Seems that I'm not quite getting the knack of this.

    The idea is to have the cannon rotate between two points. Once the mouse/touch is released, the bullet flies out based on the direction the cannon was aimed, and the scrollTo function follows it.

    I've created a dummy object that gets destroyed when the mouse-click is released, and instead spawns the actual flying object.

    Ideally:

    1. As mouse button is pressed, energy increases to a max of 100 (done)

    2. Cannon stops when mouse button is released

    3. Object shoots out in the direction the cannon was aimed, at the speed set by the energy

    5. ScrollTo follows object

    6. Object is affected by gravity

    7. Cannot create additional flying objects until it game is over (object crashes)

    Next steps:

    Create a visual "flight bar" that gives air push to the object when mouse/touch is pressed, but decreases in value.

    cannon_test.capx

    Your help is greatly appreciated.

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