So in my game I have the character move 0.1 per tick. The problem is that
when i calculate the distance to the destination, the results seem all out
of wack when distance < 0.
heres my results:
moved. distance from destination,(208, 321)=1.03817816236 velocity: 0.1
distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.943491350926 velocity: 0.1
distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.850022330142 velocity: 0.1
distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.758221599671 velocity: 0.1
distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.668776514745 velocity: 0.1
distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.582772733699 velocity: 0.1
distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.501982162641 velocity: 0.1
distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.429357804259 velocity: 0.1
distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.36974336579 velocity: 0.1
distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.330260789397 velocity: 0.1
distance from old pos: 0.1
------->moved. distance from destination,(208, 321)=0.31848739611 velocity:
0.1 distance from old pos: 0.1
------->moved. distance from destination,(208, 321)=0.337337003527 velocity:
0.1 distance from old pos: 0.1
moved. distance from destination,(208, 321)=0.382306534624 velocity: 0.1
distance from old pos: 0.1

You can see that where I inserted arrows, the distance instead of going to
0.2 or 0.1 it skips over the destination and goes to 0.38. I dont see how
this is possible since the distance from the old position is always 0.1

here is my code:


        def updateVelocity(self):
                '''calculates the velocity/movement to be done on x and y 
during move
method'''
                #update velocity
                vx = math.cos( self.heading )* self.speed
                vy = math.sin( self.heading )* self.speed 

                self.velocity = (vx , vy )

        def move(self ):

                d = math.sqrt ( (self.pos[0] - self.destination[0])**2 + 
(self.pos[1] -
self.destination[1])**2)
                v= math.sqrt( self.velocity[0]**2+ self.velocity[1]**2 )

                if d <=self.speed: #this does not work because the d rarely 
goes below 0.3
                        self.pos = self.destination 
                else:
                        self.oldpos = self.pos
                        self.pos = ( self.pos[0] + self.velocity[0], 
self.pos[1] +
self.velocity[1] )
                        d2 = math.sqrt ( (self.pos[0] - self.oldpos[0])**2 + 
(self.pos[1] -
self.oldpos[1])**2)
                        print "moved. distance from destination," + str( 
(self.destination[0],
self.destination[1])) +"=" + str(d ) + " velocity: " + str(v) + " distance
from old pos: " + str(d2)










--
View this message in context: 
http://pygame-users.25799.n6.nabble.com/help-with-float-issue-tp331.html
Sent from the pygame-users mailing list archive at Nabble.com.

Reply via email to