Postdeleted.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
luaiscool
Prole
Posts: 34
Joined: Mon Apr 21, 2014 11:03 pm

Postdeleted.

Post by luaiscool »

*Post Delete by Me, Luaiscool*
Last edited by luaiscool on Tue May 13, 2014 2:11 am, edited 1 time in total.
http://xkcd.com/979/

Code: Select all

if signature = true then
    print(signaturetext)
else
    print("Error: Signature Not Found")
end
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: My idea on how to make a working AI

Post 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.
Last edited by Jeeper on Wed May 14, 2014 10:42 am, edited 1 time in total.
luaiscool
Prole
Posts: 34
Joined: Mon Apr 21, 2014 11:03 pm

Re: My idea on how to make a working AI

Post 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.
http://xkcd.com/979/

Code: Select all

if signature = true then
    print(signaturetext)
else
    print("Error: Signature Not Found")
end
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Postdeleted.

Post 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/
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Postdeleted.

Post 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.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Postdeleted.

Post 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.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Postdeleted.

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 230 guests