@Fred Not Bob
[EDIT - New]
Looking back at your code, it could be that because your car is moving in increments of .9 that it may never be meeting the distance requirment of .2 . If that is the case, it will keep flickering as it moves a little then points back at the destination. Try increasing
if d#<0.2
des=0
endif
to 1.8 (twice the distance the car would move in one iteration) and see if that helps. Then slowly reduce or increase the value until the car continues to respond 100% of the time.
[Old]
Hello,
Well one thing I noticed in the first snippet
`points the charachter to it's destination and moves it
if des=1 then point object 4,desx#,0,desy#:move object 4,0.9
`if the mouse is clicked, then the destination is set
if mouseclick() = 1 then desx#=x#:desy#=y#:des=1
`if the charachter object reaches its destination, then it stops
dx#=desx#-object position x(4)
dz#=desy#-object position z(4)
d#=sqrt((dx#*dx#)+(dz#*dz#))
if d#<0.2
des=0
endif
this line:
point object 4,desx#,0,desy#
I don't know if the variable desy# is meant to be a z direction or a y direction but you have desy# in the z parameter for the POINT OBJECT command. If it is meant to be a z position, then just for clarity, maybe all occurences of the variable desy# should be changed to desz# - unless there is some reason to keep it named desy#. Because later, you are interchanging z# variables with it. Just seems a bit confusing...
Also, if the y value is set to 0, the object will be pointing down if it is above 0 and up if it is below 0 - probably not what you intend.
In general, when using the POINT OBJECT command, it's a good idea to know which plain you want the object that is pointing to be on. What I mean is, if you are driving a car and it is pointing somewhere in 3d space, the actual direction you point the car in will be an x and z direction. The y value of the car won't change unless you are going over a cliff, splashing into a lake, driving up a ramp, etc.
So, if you are on flat land, you want to maintain the cars y position and point to some world x and z so the command might look like:
rem assume the variable car is assigned 4 indicating it is
rem object number 4
rem now point the car towards a world position at desx and desz
cary#=OBJECT POSITION Y(car)
POINT OBJECT car desx#,cary#,desz#
Now if you actually have to point the car up or down, then the y value might be in terms of world coordinates as well instead of the cars own y position.
Here is an example of moving a cone through waypoints. Once it reaches one, it points in the direction of the next one. Maybe it will help.
rem cone through waypoints
rem by latch grapple
rem 09/17/2007
sync on
sync rate 60
autocam off
hide mouse
randomize timer() : rem seed random generator
rem make an cone to point in the direction we are moving
car=1
make object cone car,50
xrotate object car,90
fix object pivot car
position object car,0,25,0
color object car,rgb(0,255,0)
rem make a ground for reference
make matrix 1,1000,1000,10,10
rem make a few random points as way points
dim dest(10,1) : rem store 11 points with an x and a z
for n= 0 to 10
dest(n,0)=rnd(1000) : rem x
dest(n,1)=rnd(1000) : rem z
next n
rem main
wypt=0
cary#=object position y(car)
do
rem point and move object through waypoints
point object car,dest(wypt,0),cary#,dest(wypt,1)
move object car,4
objx=object position x(car)
objz=object position z(car)
rem have camera follow cone
position camera 500,300,-500
point camera objx,cary#,obyz
rem count through way points check if the cone is within 25 units
if sqrt((dest(wypt,0)-objx)^2 + (dest(wypt,1)-objz)^2) <= 25
inc wypt
endif
if wypt > 10 then wypt=0
text 0,0,str$(wypt)
sync
loop
Enjoy your day.