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.

Author
Message
Mokraton
14
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 31st Dec 2011 06:37
I am creating artificial intelligience for a very basic game I am making for my School's Science Fair.

So far I have created a Hunt_ Function for my AI so that he will be rotated towards the Sprite current position and will automatically move there in order to chase the sprite.

I am trying to make, the AI more "human" by having actually run in front of the player so that it is like playing tag. I do not want AI to run the the current position of the player, but to slightly in front of the player based on his velocity.

My idea was that I would find the player's current rotation point and then multiply his velocity by X number of seconds to find a distance in front where I could rotate my AI to move to. It would be in a loop so that if the player suddenly turns around(which i'm sure he would) the AI will react and started heading the other direction, and not directly at the player, more towards the calculated distance in front of the player.

I compiled my project into a zip file and attached it. I havn't added much relative code to it(none really), but you can tinker with it as well as help me out. I am working on figuring it out, but I havn't learned trigonometry yet, so I'm having to self-teach myself this. (I don't even know if trig is involved)

Beginning Programmer
Professional Nerd
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 31st Dec 2011 12:20 Edited at: 31st Dec 2011 12:21
Hi Mokraton, well, it may be time to learn a bit of trigonometry.

Since you have already got a 'hunting' algroithm working, we can go straight to working out the point to 'hunt' towards. Try something like this:

x = cos(player_angle) * distance_from_player + player_x_position
y = sin(player_angle) * distance_from_player + player_y_position

Then set your hunter to move towards the x and y coordinates. The distance_from_player is how far infront of your player you want the hunter to move towards.

Edit- a further explanation can be found here.

Login to post a reply

Server time is: 2026-07-10 00:42:59
Your offset time is: 2026-07-10 00:42:59