Page 1 of 1

Postdeleted.

Posted: Mon May 12, 2014 9:37 pm
by luaiscool
*Post Delete by Me, Luaiscool*

Re: My idea on how to make a working AI

Posted: Tue May 13, 2014 12:44 am
by Jeeper
How you make an AI depends on what type of game it is that you are making. I am going to assume that what you are trying to do is get an enemy to move to the player, if this is the case then your code does not work. In other terms, your code is as flawed as asking "Do we have enough fuel to drive from point A to point B if our car has room for 4 people?".

Your code is asking "Is the player position over 5". And if the player.x is over 5 then you move the enemy on both its X and Y axis. What it should be asking is "is the player position over the enemy position" and move the enemy accordingly. Check the Y position and X position separately and then move accordingly. I will try to give you an example of how to do it for the X position.


Code: Select all

   if player.x > enemy.x then
        enemy.x = enemy.x + enemy.speed * dt
   elseif player.x < enemy.x then
        enemy.x = enemy.x - enemy.speed * dt
   end
You will obviously have more than 1 enemy I assume, in that case you need to check the enemy table with a forloop.

Last I can say that using the code I posted about will make the enemy "jitter" when he reaches his final destination as the enemy will always overshoot the destination and keep going back and forth. So you need to add in so that it asks if the condition will be met even after the enemy has moved. Something like this:

Code: Select all

    if enemy.x > player.x and enemy.x + enemy.speed * dt > player.x then
          enemy.x = enemy.x - enemy.speed
    elseif enemy.x > player.x and enemy.x + enemy.speed * dt < player.x then
          enemy.x = player.x
    end
Let me know if you didn't understand it. I also would recommend that you do not try to "teach" people how to do certain things when the code that you have is simply wrong. I know that you have no bad intentions and I am not trying to bash you for asking "noob questions" or anything, feel free to ask as much as you like. No question is too stupid.

Re: My idea on how to make a working AI

Posted: Tue May 13, 2014 2:09 am
by luaiscool
Jeeper wrote:How you make an AI depends on what type of game it is that you are making. I am going to assume that what you are trying to do is get an enemy to move to the player, if this is the case then your code does not work. In fact the code that you posted makes no sense on any level.
In other terms, your code is as flawed as asking "Do we have enough fuel to drive from point A to point B if our car has room for 4 people?".

Your code is asking "Is the player position over 5". And if the player.x is over 5 then you move the enemy on both its X and Y axis. What it should be asking is "is the player position over the enemy position" and move the enemy accordingly. Check the Y position and X position separately and then move accordingly. I will try to give you an example of how to do it for the X position.


Code: Select all

   if player.x > enemy.x then
        enemy.x = enemy.x + enemy.speed * dt
   elseif player.x < enemy.x then
        enemy.x = enemy.x - enemy.speed * dt
   end
You will obviously have more than 1 enemy I assume, in that case you need to check the enemy table with a forloop.

Last I can say that using the code I posted about will make the enemy "jitter" when he reaches his final destination as the enemy will always overshoot the destination and keep going back and forth. So you need to add in so that it asks if the condition will be met even after the enemy has moved. Something like this:

Code: Select all

    if enemy.x > player.x and enemy.x + enemy.speed * dt > player.x then
          enemy.x = enemy.x - enemy.speed
    elseif enemy.x > player.x and enemy.x + enemy.speed * dt < player.x then
          enemy.x = player.x
    end
Let me know if you didn't understand it. I also would recommend that you do not try to "teach" people how to do certain things when the code that you have is simply wrong. I know that you have no bad intentions and I am not trying to bash you for asking "noob questions" or anything, feel free to ask as much as you like. No question is too stupid.
Yeah i see what you mean. My main intension sort of like a proof of concept on a way to make the enemy move. To be honest, I seem to do stupid things durin the say but at night I'm more alert and actually think straight. I'll probaby take down this post. Actually yeah im gonna try to delete this.

Re: Postdeleted.

Posted: Wed May 14, 2014 1:51 am
by Inny
luaiscool wrote:*Post Delete by Me, Luaiscool*
Aww dude, don't delete your posts. This was some valuable information that future users of this forum may want to search for. You should see this xkcd comic: http://xkcd.com/979/

Re: Postdeleted.

Posted: Wed May 14, 2014 6:03 am
by Jasoco
Yeah, please don't delete posts once a problem is solved or forgotten. It just causes grief when others are looking for answers.

Re: Postdeleted.

Posted: Mon May 19, 2014 11:56 pm
by Lafolie
Inny wrote: Aww dude, don't delete your posts. This was some valuable information that future users of this forum may want to search for. You should see this xkcd comic: http://xkcd.com/979/
I love that the alt text for that one basically describes a wiki.

Re: Postdeleted.

Posted: Tue May 20, 2014 2:04 am
by Inny
Lafolie wrote:
Inny wrote: Aww dude, don't delete your posts. This was some valuable information that future users of this forum may want to search for. You should see this xkcd comic: http://xkcd.com/979/
I love that the alt text for that one basically describes a wiki.
Well it's basically how StackOverflow works. Worked. The site can't be referred to as working anymore, but for all posts made before 2014, people were really good at marking down what they decided to be the correct answer.