# Moving UV in BGE

After watching many tutorials I've bumped into one from which i've learned that it is possible to move UV unwrap over the texture. And the .py looks like below:

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
mesh = own.meshes
verts = mesh.getVertexArrayLength(0)
for i in range(0, verts):
point = mesh.getVertex(0, i)
uv = point.getUV()
uv += own['x']/100
uv += own['y']/100
point.setUV(uv)


Wanted to ask is there a way of how to move individual vertex points in a similar manner?

Noob

The code you show goes trough every vertex then manipulate it. To manipulate a single vertex, you just have to "skip" the for loop ; something like that :

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
mesh = own.meshes
# verts = mesh.getVertexArrayLength(0) #we don't need that anymore

i = 0 #the index of the vertex we want to manipulate. 0 is the first one
point = mesh.getVertex(0, i)
uv = point.getUV()
uv += own['x']/100
uv += own['y']/100
point.setUV(uv)

i = 1 #the index of the vertex we want to manipulate. 1 is the second one
point = mesh.getVertex(0, i)
uv = point.getUV()
uv += own['x']/100
uv += own['y']/100
point.setUV(uv)

# ...and repeat with i=2, i=3 etc


This code should work (i can't test it right now), but is not very robust. What appends if you try to manipulate a vertex that doesn't exist ?

As the code repeats a lot, you can wrap some of it in a function, like that :

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
mesh = own.meshes

move_uv(0, 0.5, 0.0)  #move the first vertex 0.5 right
move_uv(1, 0.0, -0.5) #move the second vertex 0.5 down
move_uv(2, 0.1, -0.1) #... and so on

def move_uv(index, moveX, moveY):
point = mesh.getVertex(0, index)
uv = point.getUV()
uv += moveX
uv += moveY
point.setUV(uv)

• Yay! Thanks for Your help and answer! It looks like the top right vert is moving upwards if x is set on 0.1 while it is a float property.
– Noob
Apr 2, 2022 at 12:56
• And now by adding positive or negative values to x and y, I can position it sort of the way I want. But could You help me to add rest of the 3 vertex points into this script? As I've got no idea where to even start. As I understand I would need to add 3 more properties to the object isn't it? And I guess to rename x as x1 as well as y1 and continue with x2 and y2, then x3 with y3 and x4 with y4 to make it less confusing. How can I set index of second, third and fourth?
– Noob
Apr 2, 2022 at 13:20
• I guess somehow i need to find out how to get vertex list of the object :o
– Noob
Apr 2, 2022 at 13:28
• I edited my answer to show how to move the other vertices. The code is ugly as hell but should do the job. Apr 2, 2022 at 13:45
• That is absolutely wicked. I've just renamed the x and y props in separate sets as x1, y1, to x4, y4 and added values in them to see which one is which one and if they are doing the intended, and seems like everything is working perfectly. I've just noticed Your edit and the function to move it on already set values which is quite helpful. As i won't need to mess with timed objects adding values to properties to move it by particular values. Thank You so much! I will definitely chk it and try that as well.
– Noob
Apr 2, 2022 at 13:59