Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Racing game: Calculating angles using atanfull

Author
Message
LeeTC
17
Years of Service
User Offline
Joined: 20th Oct 2006
Location:
Posted: 4th Mar 2007 15:25
Finding myself mega stressed with this! I have a car game with a player controlled car sprite and a computer controlled enemy car sprite. My track has several checkpoints which the player must cross through to successfully complete a lap.

I'm trying to get the enemy car to aim towards the centre of the checkpoints by grabbing the position of each, the position of the car, and using atanfull to calculate the angle between the two. I've then used a few if statements to determine the direction the car should steer. Once the enemy car passes through a checkpoint, it aims for the nexst one. Or at least that's the sudo behind it.

It's all become very messy - double if's to prevent the car doing a 360 to get to the checkpoint and limiting the amount of lock on a turn, neither of which seems to be helping me.

I'm convinced something's wrong with my atanfull but for the life of me I can't figure out what. I've tried adding 90 to make sure the points are synchronised (i.e. 0 degreesfor the car is the same as 0 degrees for the checkpoint)

I've attached car.zip which has everything I'm working with so far [in Dark Basic Pro]. Any help would be greatly appreciated.

Many, many thanks in advance.

Attachments

Login to view attachments
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 4th Mar 2007 19:07
Try something like this. In this demo the triangle will try and get the mouse. If you pretend the mouse is a checkpoint and the triangle is a car you can use the same logic in your game.



Hope this helps

LeeTC
17
Years of Service
User Offline
Joined: 20th Oct 2006
Location:
Posted: 5th Mar 2007 10:41
Thanks very muchos, Sixty! Turns out I was calculating the atanfull completely wrong.

However I'm still not quite there. The car does now complete a circuit, only it takes about three times longer than the players car since it can't make the checkpoints first time. I've tried increasing the amount of turn the car's allowed to put on along with how fast it can put it on, but neither make much difference.

I've attached an updated zip if anybody could help me out.

Again many thanks in advance!

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-09-25 19:24:37
Your offset time is: 2024-09-25 19:24:37