Hello miki,
EDIT (didn't see TDKs post)
TDK's method is a great way to control the opponent cars position on the track more precisely.
The Full Metal Coder has a great idea also by using curveangle() to interpolate the angle. I added a couple of lines to your example code to show how this is done. Basically, I get the angle to the next waypoint using the point object command, then I turn the object back around to it's original facing and use curveangle to graduate the two angles from object to way point.
You could use the same technique but with a hidden object at the same position as the main object that finds the angles so the only rotation that occurs on the main object is by interpolation.
Here's the adjusted code:
` example of dummy car coding
sync rate 120 : sync on : hide mouse : randomize timer()
`
` make 5 waypoints and label them with number images
cls rgb(255,255,0)
set text size 22
ink 0,0
for t = 1 to 5
make object box t,15,15,15
position object t,rnd(200),0,rnd(200)
text 10,10,str$(t)
get image t,0,0,32,32
texture object t,t
cls rgb(255,255,0)
yrotate object t,90 :` turn the number images round
next t
wp=1 :` set waypoint value to 1
`
` make dummy car
cls rgb(255,0,0)
dummy=11
make object box dummy,15,15,15
position object dummy,100,0,100
text 10,10,"D"
get image dummy,0,0,32,32
texture object dummy,player
yrotate object dummy,90
`
` set light, camera and backdrop
position camera 100,260,100 : point camera 100,0,100
make light 1
set ambient light 22
color light 0,0
color backdrop 0
do
`
` move and point player at current waypoint
move object dummy,1
rem let's adjust the snap and interpolate using curve angle
rem first get the objects current y angle
angy#=object angle y(dummy)
rem here you can use math to calculate the angle between the object
rem and the way point or you can use point object to get that angle
point object dummy,object position x(wp),object position y(wp),object position z(wp)
rem get this new y angle then point the object back to where it was
newangy#=object angle y(dummy)
yrotate object dummy,angy#
rem now interpolate the angle
finalang#=curveangle(newangy#,angy#,20)
yrotate object dummy,finalang#
`
` handle dummy collision
hit11= object collision(dummy,0)
if hit11=wp
wp=wp+1
endif
if wp>5 then lap=lap+1 : wp=1
`
` onsreen info
ink rgb(255,255,255),0
text 10,10,"current target "+str$(wp)
text 10,290,"This code snaps the angle to"
text 10,310,"point the dummy at the current waypoint."
text 10,350,"How can it be made to smooth curve?"
`
`
sync
loop
Enjoy your day.