planetary brick gravity?

ok so i want to make a “brick” that my player can stick to, but im lost as to how i could do this, ive tried some planetary gravity, but sense that pulls my player towards the center of the object it looks sloppy any suggestions?

Maybe use a script that casts a ray “down” and finds the normal of the face that is below it. Apply a force along the negative of the normal and your character should be attracted directly to the face that is below it.

To avoid errors from a complex ground mesh (hills) you could have a “gravity mesh” that sits below the ground that is sensed by the ray and the force could be calculated using the hit normal of this mesh.


You would need to figure out how to determine when the character needs to change directions, but something like this might work.

Have an object that tracks to the “brick” And then moves towards it.
Then use a rigid body joint to attach it to the character

One of the ways this can be done without logic bricks is by taking advantage of the added flexibility of the rayCast() API function, by way of doing something like casting a ray from the player to the center of the object that the player is colliding with, using the hitObject property with the collision sensor as the destination point for the ray (which the value can be stored as a separate variable so the value is kept if there’s no collision currently), and then applying force to the player according to the hitNormal property of the face being detected.

If you need to use really long objects for some reason you could possibly use collision boxes where the ray goes to the center of instead and still align the character to the face normal that is picked up.

Another possibility is that you could just use rayCast() to send a ray along a vector going down from the player and have it rotate if it’s not picking up any value for the hitNormal to try to get a new reading as long as the ray doesn’t exceed the maximum allowed distance (and the direction it rotates would depend on the direction the player is going)

@FunkyWyrm
i have tried that and i think the problem i get is when i get to the edge of the brick the ray misses it and cant get the normal. maybe if i put more rays out to the sides of the character?

@Ace Dragon
I COMPLETELY FORGOT RAYCAST!!! haha Thank you!

I was thinking about rayCast. It can recall all sorts or useful information, far more than just the hit object.

rayCast is quite a heavy function to call, but since this effect is one of your primary game mechanics you could probably get away with casting more rays that would be advisable in many other games.

If the first rayCast doesn’t hit anything, perhaps send out 4 rays (maybe 8?) at 45 degrees from the downwards direction. If the character is currently in a standard vertical orientation, these rays would be along [x,y,-z], [x,-y,-z], [-x, -y, -z] and [-x, y, -z] if using 4 rays and additionally [0, y, -z], [x, 0, -z], [-x, 0, -z] and [0, -y, -z] if using 8 rays. These rays would be able to still find the ground even when the character jumps off the edge.

It seems to me that traversing the edges in a fluid way is the biggest challenge in your game mechanic.

glow.blend (305 KB)ok so now im getting some errors that are really annoying iv’e tried fixing them but i cant find out how to fix the problem, here is the blend(sorry for sloppiness)

hate to do this but…bump