Good day community! I require your assistance on this one.
You see, I’ve been working on this script which sets the camera to follow an object and moves around it, always focusing the object.
Before anything else I am working on a space-planets environment game.
This is the code I am working with (not fnished):
import bge, math from bge import logic cont = logic.getCurrentController() own = cont.owner scene = logic.getCurrentScene() obj = scene.objects player = obj["player"] gd = logic.globalDict vectto = own.getVectTo(player) own.alignAxisToVect([0.0, 0.0, 1.0], 2, 0.15) # I Require help with this line own.alignAxisToVect(vectto, 1, 0.15) x = player.position + gd["radius"] * math.cos(gd["theta"]) * math.sin(gd["phi"]) y = player.position + gd["radius"] * math.sin(gd["theta"]) * math.sin(gd["phi"]) z = player.position + gd["radius"] * math.cos(gd["phi"]) own.position = [x, y, z]
As you can see in the line 13 I am aligning the object’s local z axis to the world’s positive z axis, but that is not what I want to achieve.
What I want to achieve are these 2 things:
1.- Align this object (own) local z axis to the second object (player) local z axis, this to simulate space flight.
2.- Align this object (own) local z axis to the vector from the planet to the player, this is because it walks on a planet.
I have a second script where I calculate the vector to align the player to the planet:
from bge import logic import math from mathutils import Vector cont = logic.getCurrentController() own = cont.owner scene = logic.getCurrentScene() for obj in scene.objects: if 'alignToSurface' in obj and obj['alignToSurface'] == True: xDist = obj.worldPosition - own.worldPosition yDist = obj.worldPosition - own.worldPosition zDist = obj.worldPosition - own.worldPosition distSquared = (xDist)**2 + (yDist)**2 + (zDist)**2 dist = math.sqrt(distSquared) if dist <= 20: align = own.getVectTo(obj) obj.alignAxisToVect(align, 2, 0.15)