Problem with track to nearest property with planetary gravity

i assumed the gravity script had an alignment. the point of my post was that the Z needs to happen SECOND.

but having two aligns should work. when i get to my pc ill do some experimenting.

running a print on the gravity script and the ai will tell you which script is running first. just exit right after the game starts to keep the console from running out.

well in general it should work, but in his blend when i did use z axis to track up(last week), it didn’t work either, the follower kept tilting forwards/to the sides.

I am interested in your experiment.i want the problem resolved.

when creating a demo file, i realized the gravity script shouldnt align objects as this would be physically odd. so i just passed the vector along to each object through a property. then players and ai can take it and align themselves at a specific point in the code.

here is the example i came up with. most of the code is order specific, especially the z align on the player script. movement and rotation wont work if the align is after.

planetary_gravity_dae.blend (2.5 MB)

but keyboard.events are depricated.that is what is in the console.what are version of blender are you using? i am using upbe 0.2.3.

i use 2.74. it should be easy enough to update the keyboard input, last i checked .events still works fine enough.

console also Says in what you need to change it, so do it xD

i tried placing my animated characters in your blend and the animations keep playing for the player character.does that happen with capsule physics?

here is the blendfile.planetary_gravity_dae.zip (9.2 MB)
it only works for perfectly round planet.the player spins around if the planet is not perfectly round.

Got no time atm to look at it, maybe later or tomorrow, the blend was from @Daedalus_MDW, maybe he can take a look, else i will do when i got time.

No physics has nothing to do with it (capsule or dynamic, etc)

okay I will wait.

from what i can tell, it seems to work ok in upbge 0.2.3.

the entire thing is a pure disaster, you might want to start there. so much logic everywhere im not surprised it doesnt work right. really take time to evaluate whats going on, then organize your logic.

give everything a name

blender has this problem with parenting, if you reselect the parent object from the object properties (relations) then it will reset to relative coordinates.

lots of objects have unapplied scale.

what i am using is upbge 0.2.3.no it does not work in upbge 0.2.3.you said I did in the first

sentence.

if you are talking about the mouse coordinate offset bug (drifting), then thats fault of upbge.

you can delete the mouse look section of code and use an actuator for a quick fix.

big update:
-added raycast enhanced stability to prevent dropping through the planet.
-demo of animations.
-improved object structure to more closely resemble actual usage.
-sample content.
-mouselook fix

known issues:
-jumping can glitch if running up a slope or if the character never leaves the ground.
-excessive use of ‘get()’ to find object properties. init function recommended.

planetary_gravity_dae_v2.blend (3.0 MB)

NOTE: methods, animations, and models derived from https://github.com/DaedalusMDW/bge_game-3.0_template

forget what I was trying to say recently it aready has it.

it lacks one thing that I want implemented.a track to nearest property script.i will try to implement it.if I get stuck I will ask for help.

i tried but it spit out error I do not understand.
here is the code.

from bge import logic, events

from mathutils import Vector


def PLAYER(cont):

	owner = cont.owner
	scene = owner.scene
	armature = owner.children["Actor.Rig"]

	G_VEC(owner)

	## Movement ##
	kbe = logic.keyboard.events
	move = Vector((0,0))
	is_gnd = owner.get("IS_GND", "FALSE")


	if kbe[events.WKEY] == 2:
		move[1] = 1
		ACTION(armature, "Running", (0,39), 2, "LOOP", 10)
	elif kbe[events.SKEY] == 2:
		move[1] = -1
		ACTION(armature, "Running", (39,0), 2, "LOOP", 10)
	elif is_gnd == "FALSE":
		ACTION(armature, "Jumping", (20,20), 2, "LOOP", 10)
	else:
		ACTION(armature, "Jumping", (0,0), 2, "LOOP", 10)

	if kbe[events.AKEY] == 2:
		move[0] = -1
	elif kbe[events.DKEY] == 2:
		move[0] = 1

	if kbe[events.SPACEKEY] == 1 and is_gnd == "TRUE":
		ACTION(armature, "Jumping", (0,20), 1, "PLAY", 10)
		owner.setDamping(0.5, 0.5)
		owner.setLinearVelocity((0,0,5), True)
		owner["IS_GND"] = "NONE"

	move.normalize()
	owner.applyMovement((move[0]*0.1,move[1]*0.1,0), True)


def AI(cont):

	owner = cont.owner
	scene = owner.scene
	armature = owner.children["Actor.Rig.001"]
    ai = [obj for obj in scene.objects if 'track_to' in obj]
    if ai:
    closest_ai      = sorted(ai, key=lambda enemy: own.getDistanceTo(enemy))[0]

	dist, glv, lcv = owner.getVectTo(scene.objects["Player"])
	if dist >= 2:
		move = (dist-2)*0.1
		if move >= 0.1:
			move = 0.1

		if move > 0.05:
        
        dist  = own['track_distance'] 

        elif dist <= max_dist:

			ACTION(armature, "Running", (0,39), 2, "LOOP", 10)
		elif move > 0.01:
			ACTION(armature, "Walking", (0,59), 2, "LOOP", 10)
		else:
			ACTION(armature, "Jumping", (0,0), 2, "LOOP", 10)

		owner.applyMovement((0,move,0), True)

	owner.alignAxisToVect(glv, 1, 0.5)

	G_VEC(owner)


# Align Objects to Ground
def G_VEC(owner):
	zref = owner.get("G_VEC", None)
	rayto = owner.children[owner.name+".GroundRay"]

	## Align to Gravity (MUST BE FIRST!) ##
	if zref != None:
		owner.alignAxisToVect(zref, 2, 1.0)

	## Ground Stability (MUST BE SECOND!) ##
	rayOBJ, rayPNT, rayNRM = owner.rayCast(rayto, None, 1.1, "", 1, 0, 0)

	if rayOBJ != None:
		if owner.get("IS_GND", "FALSE") != "NONE":
			owner["IS_GND"] = "TRUE"
			owner.setDamping(1.0, 1.0)
			owner.applyForce((zref*9.8*owner.mass), False)
			owner.worldPosition = rayPNT+(zref*1)
	else:
		owner.setDamping(0.5, 0.5)
		owner["IS_GND"] = "FALSE"


# Play Action
def ACTION(OBJECT, NAME=None, FRAME=(0,0), PRIORITY=0, MODE="PLAY", BLEND=0, STOP=False):

	if STOP == True:
		OBJECT.stopAction(LAYER)
		return

	if NAME == None:
		NAME = OBJECT.name

	LAYER = 0
	SPEED = 1
	LYRWGHT = 0
	IPO_FLG = 0

	if MODE == "PLAY":
		PLAYTYPE = logic.KX_ACTION_MODE_PLAY

	elif MODE == "LOOP":
		PLAYTYPE = logic.KX_ACTION_MODE_LOOP

	BLENDTYPE = logic.KX_ACTION_BLEND_BLEND

	OBJECT.playAction(NAME, FRAME[0], FRAME[1], LAYER, PRIORITY, BLEND, PLAYTYPE, LYRWGHT, IPO_FLG, SPEED, BLENDTYPE)

thats definitely not right. learn about python syntax and indentation, especially with if/then statements. note that i use tabs, and you cant mix tabs and spaces. (ctrl T in text editor, disable “tabs as spaces”)

i wont be at my pc for a few hours, but ill get it fixed.

i know that if I use if elif has to be after.and else for doing something if no if or else statement is true. I will wait for your response.