Fangames > Programming Questions

AI Question

(1/1)

N3ON:
Okay, before i begin, i wanna say that i understand a fair amount of programming, when it comes to game maker: studio, with around 332 hours in the program, but I have no idea how i would get this to work.

Basically, i want to make an object that moves towards the player, but instead of instantly changing it's direction to always move towards the player, i want the object to overshoot if the player dodges, and turn around to try again, like sonic from IWBTB, or this example i found:


As I said, I have no idea where to start with something like this, so any help will be appreciated.

Nogard:
You could use the built in gravity_direction to have the desired behaviour.

Set the gravity in the create event, and in the step event have the line:


--- Code: ---with(objPlayer)
  other.gravity_direction=point_direction(other.x,other.y,x,y);

--- End code ---

So that the acceleration of your object is always pointing towards the player.
If you don't want said object to get too far away from the player I suggest also putting a cap on its speed.

N3ON:

--- Quote from: Nogard on December 18, 2016, 02:47:57 PM ---You could use the built in gravity_direction to have the desired behaviour.

Set the gravity in the create event, and in the step event have the line:


--- Code: ---with(objPlayer)
  other.gravity_direction=point_direction(other.x,other.y,x,y);

--- End code ---

So that the acceleration of your object is always pointing towards the player.
If you don't want said object to get too far away from the player I suggest also putting a cap on its speed.

--- End quote ---

This worked surprisingly well! Thanks!  :atkHappy:

Navigation

[0] Message Index

Go to full version