Page 1 of 1

Grapple Gun

PostPosted: Thu Jul 14, 2011 9:33 pm
by jimmynewguy
I've always wanted to implement a grappling gun into a game, but never did. So I got bored and made one for kicks, and thought I'd share.

Re: Grapple Gun

PostPosted: Thu Jul 14, 2011 9:39 pm
by Hblade
interesting! :) I remember a long time ago, sgt.sparky made something similar. Good job :D I'd never understand the physics of it.

Re: Grapple Gun

PostPosted: Thu Jul 14, 2011 9:51 pm
by jimmynewguy
Haha, it's okay. But there really aren't "physics" to it. Plus I like trying to explain things so I'll try for you (and anyone else) line by line;

Code: Select all
int num = distance(player.x, player.y, mouse.x, mouse.y)/6;

This makes the variable num = the number of chains we need to get from point a to point b. It's the distance/6 because a chain is 6 pixels long.
Code: Select all
int i;

makes the variable i for the loop
Code: Select all
angle = direction(player.x, player.y, mouse.x, mouse.y);

gets the angle that the player will be heading
Code: Select all
if(!hooks)

If we don't have any hooks (so you cannot just keep shooting)
Code: Select all
breaks = 0;
player.angle = angle;
player.directional_velocity = 6;

all this together because its simple. We reset the breaks variable in case it was triggered last shot, set the player's angle, and make him go
Code: Select all
for(i=0;i<num;i++)

a loop for the number of chains
Code: Select all
Actor * this = CreateActor("hook", "chain_01", "(none)", "(none)", player.x, player.y, true);

make the chain at the player's and y and make it called "this" temporarily
Code: Select all
this->angle = angle;

set the chains angle
Code: Select all
this->directional_velocity = 7.5 * i;

make it as fast as it's number. In other words were making it 7.5 pixels away from the last created chain (7.5 so theres a little gap between chains for visual)
Code: Select all
this->animpos = angle/10;

set the chain's animation position

then when the chain is drawn we stop it from moving in the draw actor script and when there are no more hooks the player has gravity in his draw actor

sorry hblade I know some of that is obvious to you since you've used GE before, but others might not understand. I never saw sgt. sparkys though, his was probably better since mine doesn't have a distance limit and you can sometimes go through the ground a little if shot at the right angle. It would just make it more confusing for an example if I did all that though

Re: Grapple Gun

PostPosted: Thu Jul 14, 2011 11:29 pm
by Hblade
Thank you so much :) And hehe, I dont really have a lot of time to program so that tutorial was helpful in more ways than 1. You know how to explain things pretty good :) Thanks

Re: Grapple Gun

PostPosted: Thu Jul 14, 2011 11:35 pm
by jimmynewguy
No problem! Thanks for actually downloading things I make :) nothing's worse than no replies, I'd rather have people say it sucks!

Re: Grapple Gun

PostPosted: Fri Jul 15, 2011 6:53 am
by Hblade
Lol I know that feeling :P

Re: Grapple Gun

PostPosted: Sun Jul 17, 2011 2:56 am
by Jagmaster
Haha, Sweet!

I would have replied but my internet was down XD.

Mind if I use? I think it would make a good vine or rope or something like that. How would you make an actor "Stick" to a vine anyway? I tried dissecting (Or mutilating :P)
Dst's snake bone thing and having the player parent on to one of the bones. That did not work :(. Any suggestions?

Re: Grapple Gun

PostPosted: Tue Jul 19, 2011 9:28 am
by sunnybubblegum
Super neat! I was having fun trying to swing non-stop.

How hard would it be to make it so that you can travel only part of the chain's distance? Like say on left-click up, the chain disappears and you're free to grapple to another spot. Do you see what I mean?

I like the look of the animations as well. Great job!

Re: Grapple Gun

PostPosted: Tue Jul 19, 2011 11:53 am
by jimmynewguy
Super Easy.

On mousebutton up-> left
Code: Select all
DestroyActor("hook");
hooks = 0;

Re: Grapple Gun

PostPosted: Thu Jul 21, 2011 2:10 am
by SuperSonic
Wow, I'm very impressed. I tried to do something like this before but badly failed Image

Re: Grapple Gun

PostPosted: Mon Apr 02, 2012 10:27 pm
by happyjustbecause
Excuse me for the huge bump, but I was wondering if I could maybe use the chain animations that you have. And maybe some of the coding for this grapple gun, to work on my own.

So I got bored and made one for kicks, and thought I'd share.


You probably don't mind at all, but I just want to make sure.