How do I make a laser sight?

Get help using Construct 2

Post » Sat Oct 04, 2014 4:19 pm

Am trying to add a laser guide to a gun. I want the laser to stretch until it collides with anything on the layer. but the problem is i have no idea what to do and i cant find any tutorials to help me on this. Also if you do know how to do this could you explain how it works too?
B
3
Posts: 2
Reputation: 179

Post » Sat Oct 04, 2014 5:42 pm

This a sample I had saved from a public posting. I did not write it but, should get you started.
You do not have the required permissions to view the files attached to this post.
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,283

Post » Sat Oct 04, 2014 5:44 pm

@Gravitycat

this is a very basic one...
You do not have the required permissions to view the files attached to this post.
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Sat Oct 04, 2014 5:48 pm

@TheDom
i wont recomend using this method... its more cpu intensive...at least for mobile, it works very well, but my method is more optimize... :) no offense
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Sat Oct 04, 2014 6:05 pm

Non taken and thanks for sharing
B
75
S
23
G
3
Posts: 673
Reputation: 9,283

Post » Sat Oct 04, 2014 7:55 pm

Thank you so much Lunatrap it works great. :D
B
3
Posts: 2
Reputation: 179

Post » Sun Oct 05, 2014 2:56 am

@Gravitycat

NP :)
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Sun Oct 05, 2014 12:44 pm

I didn't check lunatrap's capx (don't have the latest c2 installed), but if it's not using rex's light behaviour then I'd recommend you use that instead of an event-based solution - it's much easier & seems more efficient with lots of laser bounces:

behavior-rex-light_t105880

Just apply the Light behaviour to your laser sprite (a thin sprite with the origin at the left side), & with one action it will extend towards a custom obstacle or a sprite with the solid behaviour. You can do this every tick or manually.

After the laser has hit, you then get the hit object's UID, hitX, hitY & a reflection angle (eg. to pick the hit object you would do: Spritename | Pick instance with UID Laser.Light.HitUID)
B
27
S
12
G
1
Posts: 157
Reputation: 3,359


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 16 guests