grapple gun?

Blitz3D Forums/Blitz3D Programming/grapple gun?

asdfasdf(Posted 2005) [#1]
I am trying to make a grappel gun that if it hits a non-moving object it will bring you to it. But if you hit a movable object that is light enough to move the grapple gun will bring it you. I have no idea on how to code it. How do you do it?


octothorpe(Posted 2005) [#2]
Give all your objects a boolean field "can_be_grappled". Alternately, you could add fields for "moving" and "weight" and add a const for the "max_grapple_pull_weight".

Typically, a player cannot move while firing a grappling gun, which makes things considerably easier. Use a finite state machine to track whether the player is "free", "firing grapple", "being pulled by grapple", or "waiting for grapple return".

During normal play - while the state is "free" - process your player input normally and let him move around and fire weapons.

When the grappling gun is fired, set his state to "firing grapple". Your player update routine should now do nothing except wait for the grappling hook to collide with something or reach its maximum length.

When the hook hits something, check if it \can_be_grappled. If not, change the player's state to "being pulled by grapple" - in this state, the player update routine should move the player toward the object until he collides with it. If the object can be grappled, change your player's state to "waiting for grapple return" and record a pointer to the object it struck - in this state, the player update routine should move the object (and the hook) toward the player until it collides with him. When finished, set the state back to "free".

Make sense?


Shambler(Posted 2005) [#3]
I would like to add,

when the grapple hits a 'can be grappled' object then turn off collisions for that object and parent it to the grapple.

The object will then follow the grapple back to the player, at which point unparent the object and let it fall to the floor ( or put it in inventory ).