move towards point

Blitz3D Forums/Blitz3D Programming/move towards point

nadia(Posted 2003) [#1]
Hi,
I’m looking for some routine, which turns, moves an entity towards a target point and one can supply a turn softening parameter, to indicate how fast the entity should turn towards the new target point. I know I have seen this kind of routine floating around here before and I did a search for it, but I can’t seem to find it. And I could probably also hack something like this together myself. But why reinventing the wheel? ;-)

Thanx a lot for any response!


Stevie G(Posted 2003) [#2]
Do you want the entity to turn and face the target before it moves and then stop within a certain distance of the target or do you want it to turn and move at the same time (i.e. like a car following a waypoint)?

Not tested this code but it should give you an idea of what you need to do?

global temp_pivot=createpivot()

function move_to_point(entity,x,y,z,turn_speed#=.01, move_speed#=.1, stop_range#=1)

positionentity temp_pivot,x,y,z

if entitydistance(entity,temp_pivot) > stop_range

yaw#=deltayaw(entity,temp_pivot)
pitch#=deltapitch(entity,temp_pivot)
turnentity entity , pitch*turn_speed , yaw*turn_speed,0
moveentity entity,0,0,move_speed

endif

end function


DarkEagle(Posted 2003) [#3]
Function PointAtLocation(entity,x#,y#,z#,soft#)

mypiv = createpivot()
markerpiv = createpivot()

positionentity markerpiv,x,y,z
positionentity mypiv,entityx(entity),entityy(entity),entityz(entity)
entityparent mypiv,entity

pointentity mypiv,markerpiv

pit# = entitypitch(mypiv)
yaw# = entityyaw(mypiv)

turnentity entity,pit*soft,yaw*soft,0

freeentity mypiv
freeentity markerpiv

return sqr(pit*pit + yaw*yaw)

end function


this code will return how far from pointing at the target the entity is so you can move based on that information.


nadia(Posted 2003) [#4]
Thanks for the quick help guys!
I'll try the above code out.


Ross C(Posted 2003) [#5]
try this too, but i think dark eagles is alot tidier :)

http://www.blitzbasic.com/bbs/posts.php?topic=24472