circus cannon

Get help using Construct 2

Post » Fri May 31, 2013 5:57 pm

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.flaye2013-05-31 18:00:15
B
19
S
5
G
6
Posts: 32
Reputation: 4,194

Post » Fri May 31, 2013 6:40 pm

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.
B
19
S
5
G
6
Posts: 32
Reputation: 4,194

Post » Fri May 31, 2013 7:01 pm

Hi Flaye,

I have a solution to your cannon problem.

LIVE
http://drappdev.net46.net/Construct2/MySolutions/topic68707/

Capx
http://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
B
13
S
4
G
3
Posts: 21
Reputation: 2,134

Post » Fri May 31, 2013 7:29 pm

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:
http://www.youtube.com/watch?v=FicmaDWQRfE

Thanks.
B
19
S
5
G
6
Posts: 32
Reputation: 4,194

Post » Fri May 31, 2013 7:42 pm

[QUOTE=flaye] I'm assuming I should use a bullet object with physics, since I want a parabolic arc.[/QUOTE]

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
B
13
S
4
G
3
Posts: 21
Reputation: 2,134

Post » Fri May 31, 2013 7:55 pm

@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.flaye2013-05-31 20:05:50
B
19
S
5
G
6
Posts: 32
Reputation: 4,194

Post » Tue Jun 04, 2013 12:45 am

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.

B
19
S
5
G
6
Posts: 32
Reputation: 4,194


Return to How do I....?

Who is online

Users browsing this forum: pcprice76, smlyldz and 9 guests