# Performing a loop (e.g. like Sonic) within BGE

Hi guys-

How do you trick the BGE into allowing objects to perform loops? Although my game does not require this, someone on another forum making a similar game asked me how this might be done, and I was curious.

I assume the effect would require a local -Z force along with aligning to the normal of the object below (and no gravity-i.e. set to 0).

Cheers

Paul

I dont’ think you should do anything special… if the object is moving fast enough it should be able to make through the loop…

I think he means go around the loop, not through it, like you would on a rollercoaster, etc…

You could use a ray connected to a module controller which runs a method to align the player to the ground, and then apply “gravity” in local co-ordinates to make sure the player sticks to the surface as though gravity was acting in the direction of the normal, then apply your players movements, etc.

There is more to be said on this, like the problems with the fact that the loop, in 3D, will actually return to the ground to the side of where it left, so you’d need to add a component in that direction too. Also, you could just use IPOs instead of physics, for greater control. (If you parented your model to a “no collision” cube, then to the physics object, you could come to a loop (detected perhaps by a property on the loop or collision volume) then play an IPO on the "no collision cube, taking the player with it, but not using it’s physics) then use a property to keep track of the frame of the IPO, then when it reaches a certain frame, use a module/script to move the dynamic bounds to the end of the loop, then the player can continue. (You may wish to move the dynamic bounds first, to ensure the player returns to the correct position…)

Most games do use kind of IPOs for this. But loops are best in 2D games, 3D just kills them.

it’s relatively easy, just set world gravity to 0 and then use a align to normal script to add a force of 9.8 in the local Z axis.
I’ll link a post in a sec.

Excellent, I think I have got it working: thanks agoose77! I dont normally use emoticons but:cool:!

Now, being cheeky, how would it be possible to get the cube object in this example to stick to upside down surfaces as it moves forwards? That is, if I let go of the up cursor, instead of it falling back down it just stays there?

Cheers!

Paul

Edit- I’ve just noticed if I set the cubes gravity to local 9.8 it drops down, while if I set it to global (i.e. L button up) the script works- this is independent of the world gravity setting in the world panel. I’m a little confused!

### Attachments

gravitydefy.blend (390 KB)

OK, I dont really want to reply to my own question but:

Has the use of gravity changed in 2.57b? Because:

The example blend I just posted does this- python script aligns the cube and (in practice) setting the local z force (9.8) should allow the cube to sit wherever it stops (as global gravity is off).

But here is the problem which I cannot resolve:

If I set Z to 9.8 (positive) the cube falls
If I set Z to -9.8 (negative) the cube falls
If I set Z to GLOBAL and have Z set to 9.8 (positive) I can loop but will fall if I stop

Why does this happen? I am really wracking my brain trying to figure this out- I’ve been looking at Mario Blender Galaxy and a script by Social posted a long time ago and this really should work but it doesnt. If an object has its own gravity defined why does it fall as normal?

OK, got this sorted, a kind soul at GameBlender.org called JeroenP fidled with the script to get a really good wall clinging script.

Here it is:

### Attachments

gravitydefy_2.blend (426 KB)