I must do a program where there is an object that moves forward and backward.
I have created a script which takes from a file.txt a numbers sequence.
If it reads:
0 : go forward
1: go backward
2: stop
Can I write a script where I give a start position, an end position and a time for moving the object from start position to end position in (for example) 3 seconds? If it is possible, how can I do it?
My script is:
import bge
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
filename = open(‘filedati.txt’,‘r’)
line = filename.readline()
for word in line.split():
spostamenti = [int(e) for e in line.split()]
for i in spostamenti:
if spostamenti[i] == 0:
print(“forword”,own.position)
…script to move forward from [0,0,0] to [0,2,0] in 3 seconds…
elif spostamenti[i] == 1:
print(“backword”,own.position)
…script to move backward from [0,2,0] to [0,0,0] in 3 seconds…
elif spostamenti[i] == 2:
print(“stop”,own.position)
…script to stand still in the position in which the object is located…
main()