move to object

Blitz3D Forums/Blitz3D Programming/move to object

Picklesworth(Posted 2004) [#1]
Probably in the code archives, but I can't find it. I can't figure out how to efficiently use alignToVector for this, so is there a way to make an object move towards a point smoothly in a straight line, and then stop when it reaches there? I would prefer if I could just use an x y and z position to run the calculation too, but I'm not being picky.
Right now I have this incredibly poorly done code snippet here, which is just for testing means.
	for s.settler = each settler
	
		if s\job = job_move			
			s\dstx = order_x
			s\dsty = order_y
			s\dstz = order_z
			
			aligntovector s\picker,s\dstx,s\dsty,s\dstz,2	
			moveentity s\picker,0,0,2
			
			s\x = entityx(s\picker)
			s\z = entityz(s\picker)  						
		endif
		
		s\y = terrainheight(terrain,s\x,s\z) * 128 + 1	
		positionentity s\picker,s\x,s\y,s\z,1
		positionentity s\image,s\x,s\y,s\z,1
			
	next



N(Posted 2004) [#2]
Just trying to help, hopefully it will.

Local MoveZ#
For S.Settler = Each Settler
    If S\Job = JOB_MOVE    ;I use all capitals when referring to those sort of things
        S\DstX = S\X - Order_X
        S\DstY = S\Y - Order_Y
        S\DstZ = S\Z - Order_Z
        OrderMagnitude# = Sqr(S\DstX*S\DstX+S\DstY*S\DstY+S\DstZ*S\DstZ)
        S\DstX = S\DstX / OrderMagnitude
        S\DstY = S\DstY / OrderMagnitude
        S\DstZ = S\DstZ / OrderMagnitude
        AlignToVector S\Picker,S\DstX,S\DstY,S\DstZ,3,1  ; you're moving with a Z speed, so align it to the Z axis (3)

        If MoveZ > OrderMagnitude Then
            MoveZ = OrderMagnitude
        Else
            MoveZ = 2
        EndIf

        MoveEntity S\Picked,0,0,MoveZ
        
        S\X = EntityX(S\Picker,True)
        S\Z = EntityZ(S\Picker,True)
    EndIf

    S\Y = TerrainHeight(Terrain,S\X,S\Z) * 128 + 1
    PositionEntity S\Picker,S\X,S\Y,S\Z,True
    PositionEntity S\Image,S\X,S\Y,S\Z,True
Next


I think the problem with yours is that 1. you're aligning the entity to the X axis and 2. you're not getting the delta of the positions.

Just a guess, though, I'd have to see the problem in real-time to understand properly.


Picklesworth(Posted 2004) [#3]
okay, that's the problem basically solved. Thanks for the help :D


Picklesworth(Posted 2004) [#4]
Is there a glitch-free way to make the character stop moving once the destination is reached?


slenkar(Posted 2004) [#5]
if entitydistance(character,destination)>1
moveentity character,0,0,1

endif


Picklesworth(Posted 2004) [#6]
okay, I guess that'll have to do. Thanks. I'll just create a visible marker at the destination point, that will give me some reason to have a destination object. Thanks Slenkar


Picklesworth(Posted 2004) [#7]
the entitydistance check doesn't seem to work right... The problem is that the green cube to show me the destination is still there, and the job remains the same, which gives me the idea that it is not working.

In the following example, which I have just done in the background, the movement simply does not occur.

			if entitydistance(s\picker,s\dstThing) > 1			
				pointentity s\picker,s\dstthing
        		MoveEntity S\Picker,0,0,1
        	else
        		hideentity s\dstthing
				
				s\dstx = s\x
				s\dsty = s\y
				s\dstz = s\z
				        	
				s\job = false
			endif