Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Grapple, with seperate retract key
Grapple, with seperate retract key
2002-12-18, 4:37 PM #1
A simple, automatically retracting grapple hook cog is easy enough to either create or get a hold of, and that's fine and dandy. However, how would I go about adding a seperate retract function, like a press-to-fire, press-again-to-retract sort of system?

It's the "player can't go this far from the hook" part I just can't figure out, to create the illusion of the player being attached to a rope, which is attached to a wall/roof or whatever. Everything else I can do fine...but there really isn't much else.

Well...any ideas?

Thanks alot,
-TIE

[This message has been edited by TIE_14 (edited December 18, 2002).]
2002-12-18, 5:35 PM #2
Huh?
And when the moment is right, I'm gonna fly a kite.
2002-12-18, 5:45 PM #3
(That post was the 11000th of the cog forum. Congrats. [http://forums.massassi.net/html/smile.gif] )

Anyway...I dunno. I can't really explain it any better.
All grapple hook mods, at least all the ones I can find, "reel you in" automatically when the hook attaches itself to a surface. What I'd like to do is fire the hook, attach the hook, then have the player press a key to reel himself in. And since it's on a rope, this grapple hook, the player shouldn't be able to move any further away from the hook than he was when he shot it...because...you know...the rope won't let him.

...uh...get it?

Thanks,
-TIE
2002-12-19, 9:24 AM #4
I did something like that - except with it can't go closer. Get the vector distance of the grapple and the player and if the player tries to go farther, StopThing() the player.

To reel him in.. just do an int that changes from the first time to the second time and causes it to reel him in on the second time.
2002-12-19, 12:24 PM #5
The 11,000th post of the Cog Forum is...

Quote:
<font face="Verdana, Arial" size="2">Originally posted by GBK:
Huh?</font>


[http://forums.massassi.net/html/biggrin.gif]
Cordially,
Lord Tiberius Grismath
1473 for '1337' posts.
2002-12-19, 2:59 PM #6
Heb, if I may call you Heb - That's the kind of thing I'm going for, yeah.

Just, while I'm here, though, since I could probably test it myself, but: How much "stoppage" does StopThing create? If the hook was above you, could you swing on it, or would you freeze in the air when you reached the certain distance (rope)? Could you get a pendulum effect using this method?

Thanks either way,
-TIE

[This message has been edited by TIE_14 (edited December 19, 2002).]
2002-12-19, 4:01 PM #7
StopThing() sets the players velocity to 0/0/0 effectivly stopping him/her. However, physics then kick back in and restart from that point. (falling if in the air, sliding down a slope, ect ect) If you want the player to hang mid-air, clear the "has gravity" physic flag, then use StopThing() on the player. This will keep the player where ever he/she is at. Then use this snippet of code in a Pulse(0.001);

Code:
playervel=VectorSub(GetThingPos(hook), GetThingPos(player));

playervel=VectorSet(VectorX(playervel), VectorY(playervel), 0);

ApplyForce(player, VectorScale(playervel, 1000);


and it should give you the pendulum effect.

The first line gets the direction needed to make the player go towards the hook. The second line takes out the Z value because you don't want the player to go back to the hook, but swing instead. The third line should apply enough force to the player to overshoot the hook, then the player will be shot back, and then back, creating the pendulum effect.

You might need to adjust the int in VectorScale() so that the player overshoots the hook on the first pass. If the player doesn't overshoot the hook, no pendulum effect will be created.

[edit]You really don't need StopPlayer(), just clear the physic flag, and run that pulse. It would give the most realistic effect.[/edit]

[This message has been edited by Hell Raiser (edited December 19, 2002).]
-Hell Raiser
2002-12-19, 6:52 PM #8
Actually, I found this to work pretty well:

Code:
			dir = VectorScale(VectorNorm(VectorSub(GetThingPos(graphook), GetThingPos(player))), 10);
	
			distflex = VectorDist(GetThingPos(graphook), GetThingPos(player));

			if(distflex > distset)
			{ 
				ClearPhysicsFlags(player, 0x1);
				DetachThing(player);

				ApplyForce(player, dir);
			}	
			else	
			if(distset > distflex)
			{ 
				SetPhysicsFlags(player, 0x1);
			}


[edit - Guess I should explain it. Distset isn't assigned in this part, but it's the distance from the hook to the player when the hook attaches. This pulse pushes the player toward the hook when he's farther from it than he was when it was attached, and turns gravity on when he's closer than he was. This way, he won't fall longer than the "rope" is, and I can even emulate swining by rocking back and forth.]

But thanks, I would have never figured this out without your shove in the right direction.

-TIE

[This message has been edited by TIE_14 (edited December 20, 2002).]
2002-12-21, 5:10 AM #9
No problemo. [http://forums.massassi.net/html/smile.gif] Even I was once clueless when it came to vectors and the lot. [http://forums.massassi.net/html/wink.gif]
-Hell Raiser

↑ Up to the top!