Swing

Blitz3D Forums/Blitz3D Beginners Area/Swing

Jeepster(Posted 2006) [#1]
Ok, so I don't know too much about programming yet, but I am working on this game where you are a robot thingy and you have a grapple hook type thing and you can shoot it to swing across gaps and pull yourself up and whatnot. But, because I'm not good at programming yet, I'd like to see some sort of code where you are a box or something and you can move around and shoot a rope thing in 1st person view and then go back to a 2nd person view and be able to swing around with the arrow keys and adjust the length of rope with the mouse scroller thing. I know that seems like a really complex thing (at least it does to me), but I'd really appriciate it if somebody could point me in the right direction
Thanks
ps - I don't have a physics engine so the rope doesn't have to be very realistic - (unless you can make it realistic)


b32(Posted 2006) [#2]
Maybe you could use an animated mesh for the hook and rope? I'm sure there is some mathematical way to solve this, but I think animations would be easier.

Maybe instead of a hook, you could use a plunger (http://nyc.metblogs.com/plunger.jpg) ? Because, when it hits, say, the ceiling, it attaches itself to the same place where it hit.
A hook should withdraw a bit to get 'stuck' behind an object. That would make it more complex to get it right.

First, you could use "CameraPick camera, MouseX(), MouseY()" to determine if the mouse is aimed at an object in the scene. These objects should be made 'pickable' using EntityPickMode obj, 2. Try to export the entire scene that is 'plungable' into one file. That way you will only need to call EntityPickMode once.

If the mouse is aimed at a plungable object, you could play the first animation that fires the hook away from the robot. Instead of making short and long animations, just make a long version and pause it when the hook is more or less at the right distance. (EntityDistance)
Then you could disable the first camera and enable a second one using "CameraProjMode" or Show/HideEntity and start a second animation that swings the rope.
This animation could be played with SetAnimTime rather than Animate. For that purpose, it should be only one swing, from one side to the other. It doesn't need to slow down at the 'dead points', you can do that with code.
Let's say the swinging animation is 24 frames:
;initial swing value (max = 12)
swing# = 10

time# = time + 1
frame# = (Sin(time) * swing) + 12 ;(12=middle)
SetAnimTime grapple, frame

By adjusting the 'swing' variable, the swing will increase/decrease. You can adjust the swing with the cursor keys.
Finally, use EntityParent to stick the robot to the end of the rope. EntityParent robot, 0 will release the robot from the rope.


Jeepster(Posted 2006) [#3]
wow, nice ideas!
just one quick question...
so, lets say the robot shoots the plunger at the ceiling. Now, with the ceiling being the pickable item that it is, that would mean you could basically ONLY swing from it. But, what if I needed it so that you can also "pull" yourself straight up and down with the same plunger and ceiling meshes?


b32(Posted 2006) [#4]
I think you could make another animation where the rope is pulled towards the plunger. Then you could move the robot along with it and it will seem like he is moving up.

I was thinking about this method and I think there is a problem with the swinging part. The rope could have different lengths troughout the course. I mean, sometimes the ceiling is lower maybe and that would mean the swinging rope should be shorter.
I thought about 4 ways to deal with it:
1)You could maybe use ScaleEntity on the rope. However, scaling it too much might deform it too badly.
2)If the ceiling is closed, you could move the rope through it to hide a part of it.
3)You could also make a few rope animations with different sizes.
4)I don't know how to create a rope in a 3d editor, but maybe you could build it up out of several parts, sort of like a chain. Then using ShowEntity/HideEntity you could hide parts of the chain, to make the rope longer/shorter.


----edit-----
Okay, I was still thinking about it when I realised the maths are not that difficult when you want just a simple swinging rope. You can build the rope up out of segments and then for each segment, add it's angle to the previous ones: