Yeah, I am able to change the vertices fine, I need to be able to update it when the ground updates (from moving the whole object). Open up the .blend I put in the attachments and press space. You’ll see the vertices don’t update to the ground curves. I don’t know what the problem is, so I just guessed the origin of the object was it.
Also you’ll get an error in the .blend, I don’t think it matters much since all that’s happening is that the ray isn’t sensing the ground. Once it moves it should sense it. But it seems that it stays in the same position. Maybe the mesh stays in the same position but all the vertices move because the object moves? Then how would I update the mesh?
No, my point is that the method you’re using only moves the mesh in blender, so it doesnt affect it during the bge, whilst the MeshProxy affects in game vertices
Thanks agoose, the script looks promising, however I get this error.
Traceback (most recent call last):
File "Text", line 22, in <module>
TypeError: Matrix multiplication: not supported between 'mathutils.Matrix' and 'mathutils.Vector' types
The multiplication between, the orientation and the position isn’t working… I don’t know how to fix it because whenever I try to do position times orientation it works out fine…
Edit:
Nevermind, I fixed it with this line:
global_pos = Vector((coords+pos))*ori
Would you mind explaining the script to me please?
import bge
from mathutils import*
#GET THE MODULES
cont = bge.logic.getCurrentController()
own = cont.owner
#SCRIPT REQUIREMENTS
mesh = own.meshes[0]
vertex_length = mesh.getVertexArrayLength(0)
#GETS THE CURRENT MESH, AND THE NUMBER OF VERTICES
pos = own.worldPosition
ori = own.worldOrientation
#OBJECT POSITION AND ORIENTATION
def make_string(coord):
return(str(coord[0])+str(coord[1])+str(coord[2]))
#USES THE VERTEX COORDINATES AS A KEY, BUT KEY'S CANNOT BE Vectors,
#SO THE COORDS ARE CONVERTED TO A STRING
if not "init" in own:
own["vertices"] = {make_string(mesh.getVertex(0,v).getXYZ()):[mesh.getVertex(0,v),mesh.getVertex(0,v).getXYZ()] for v in range(vertex_length)}
own["init"] = False
#CREATES A DICTIONARY WITH THE STRING OF THE VERTEX COORDINATES AS A KEY, AND THE VALUE IS A LIST OF [VERTEX,COORDINATES]
#THIS DICTIONARY SHOULD NEVER BE CHANGED, SO ONLY RUN ONCE, BY LOOKING FOR A NON-EXISTANT VARIABLE, ALLOWING THE SCRIPT TO RUN,
#THEN CREATING THE VARIABLE SO IT DOESN'T RUN AGAIN
#FOR THE STRING ID, AND THE LIST FROM EARLIER (VERTEX_STUFF IS THE LIST)
for id,vertex_stuff in own["vertices"].items():
vertex = vertex_stuff[0] #THE VERTEX
coords = vertex_stuff[1] #THE ORIGINAL VERTEX XYZ COORDS
global_pos = ori*(coords+pos) #CONVERTS THE VERTEX COORDINATES INTO WORLD COORDINATES
end_pos = global_pos.copy() #SETS AN END POSITION AS A COPY OF THE ORIGINAL, THEN:
end_pos[2] = -10 #MODIFIES ITS Z AXIZ TO BE -10 SMALLER
offset = -0.5 #OFFSET OF THE SHADOW OBJECT FROM GROUND, IF 0, IT APPEARS TO BE "IN" GROUND
bge.render.drawLine(global_pos,end_pos,[0,1,0]) #NOT NEEEDED, USED TO INDICATE THE VERTEX COORDINATES
ray = own.rayCast(global_pos,end_pos,16) #CASTS A RAY FROM THE VERTEX GLOBAL COORDINATE TO -16 BELOW IT (IN THE DIRECTION OF "END_POS", WHICH IS ONLY -10 SMALLER IN Z
if ray[0]: #IF THE RAY HIT SOMETHING:
hitpos = ray[1] #GET THE HIT POSITION
difference =(global_pos[2]-hitpos[2])+offset #GET THE DIFFERENCE BETWEEN THE POSITION OF THE VERTEX GLOBAL COORDINATE AND THE HITPOSITION. THEN ADD THE OFFSET TO IT
end = Vector([coords[0],coords[1],coords[2]-difference]) #WHEN REMOVED FROM THE ORIGINAL VERTEX COORDINATES, THAT IS THE NEW LOCATION FOR THE VERTICES
vertex.setXYZ(end) #SETS THE NEW COORDINATES, BUT DOESN'T MODIFIY THE STORED ORIGINAL ONES IN THE DIC