How to get my car(bot) to face the car(user)

Post your coding questions such as 'how to' here.
Post Reply
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

How to get my car(bot) to face the car(user)

Post by coolw »

Ok here is my delima:

Code: Select all

turna = GetAngle (x,y,bx,by)
    If turna = Not 0 Then
        If turna >270 Then
            If bdirection + 3>360 Then bdirection = 3 Else bdirection = bdirection + (bspeed*2)
        EndIf
        If turna >0 And turna <270 Then
            If bdirection - 3<0 Then bdirection = 357 Else bdirection = bdirection - (bspeed*2)
        EndIf
    EndIf
    Text 0,36,turna
Does absolutly nothing except have the bot turn in circles. How do I get it so that the bot turn left or right depending on the angle from one car to the bot and go forward if it is directly ahead of the car?
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)
koodaaja
Moderator
Moderator
Posts: 1583
Joined: Mon Aug 27, 2007 11:24 pm
Location: Otaniemi - Mikkeli -pendelöinti

Re: How to get my car(bot) to face the car(user)

Post by koodaaja »

You must calculate the difference of the current angle and the angle to the other car;

Code: Select all

angle_to_other = WrapAngle(GetAngle(bx, by, x, y) - botangle) 
That gives you the angle to the other car from the bot car, depending on where the bot is facing.

(Wrapangle forces the angle to be between 0 and 360.)
Post Reply