Posted: Sat Apr 12, 2008 12:45 pm Post subject: Need help with AI and setting boundaries and collision detection
I am trying to create a game with platforms and have some monsters or watever walk back and forth in a set area which i want to define and when the character touches it he dies....but the place the character is jumping into also needs to be defined in a way that like lets say theres 2 platforms and the enemy is walking back and forth in between i want the platform to be defined.....let me see i mean like the platform is a rectangle and is not floating the air but touching the ground so if he walks straight into it he cant walk past it but has to jump on it, i no i would need AI for the enemies and probably collision detection for the platform part but i search and search and wen i find something its too advanced for my level its for someone elses program. IF anyone has any links orif they can just help me here then that would be great. my game is like mario and i also need the character to be able to kill the enemy like in mario by jumping on him. Please help any help is appreciated!
Sponsor Sponsor
OneOffDriveByPoster
Posted: Sat Apr 12, 2008 1:13 pm Post subject: Re: Need help with AI and setting boundaries and collision detection
What shapes are the objects? There are many posts about this subject on this forum.
It sounds like you have a lot planned, but can you put them into a list and focus on them one at a time?
Tell us what you are trying. Code would help.
Mustiko
Posted: Sun Apr 13, 2008 9:58 am Post subject: Re: Need help with AI and setting boundaries and collision detection
Well shapes theres the character but hes a picture
then theres the platform that needs to be solid so he cant pass through which is a rectangle
then theres the enemy which i want as a picture
the enemy doesnt have to like move right or left there cna be one picture where he moves back and forth between the set platforms
And now i discovered another problem I have 2 codes right now i have mario able to walk back and forth and it looks liek hes walking
that code was provided on this site and im probably gonna use it to add to my game but
my second code is for gravity becuz i need him to jump and that has many glitches
like he can jump but wen hes walking in the other code it looked liek he was walking but now in the gravity code he looks like hes still and gliding
its just one picture
also i inputed a still picture of him to the right i have one of him to the left but i dont no how to tell the code to make him still to the left when he was goign left and stopped
I have no idea how to post code in this forum becuz im new but i guess ill just copy paste it below this
This is the code for gravity and my attempt to make him walk and stuff, the picture i use of him jumping doesnt matter becuz in the end the picture uses whichever way u want him to jump.
var MainWin := Window.Open ("graphics:800,600,offscreenonly")
var key : array char of boolean
var gravity, jumpheight, speed : int
var posx, posy, velx, vely : real := 0
var onground : boolean
speed := 5
gravity := 2
jumpheight := 25
posx := maxx div 2
posy := maxy div 2
onground := false
if posy <= 100 then
posy := 100
onground := true
elsif posy >= 101 then
onground := false
end if
if key ('a') then
velx := -speed
elsif key ('d') then
velx := speed
else
velx := 0
end if
if key ('w') and onground = true then
vely := jumpheight
end if
put posx
put posy
if (velx = -speed) then
Pic.ScreenLoad ("moving left.bmp", round (posx) - 10, round (posy), picCopy)
end if
if (velx = speed) then
Pic.ScreenLoad ("moving right.bmp", round (posx) - 10, round (posy), picCopy)
end if
if (velx = 0) then
Pic.ScreenLoad ("standing still right.bmp", round (posx) - 10, round (posy), picCopy)
end if
if (vely = jumpheight) then
Pic.ScreenLoad ("moving right.bmp", round (posx) - 10, round (posy), picCopy)
end if
drawfillbox (0, 0, maxx, 100, black)
View.Update
Time.DelaySinceLast (20)
cls
end loop
A.J
Posted: Sun Apr 13, 2008 10:10 am Post subject: Re: Need help with AI and setting boundaries and collision detection
First off, enter your code between ' syntax="Turing" ' and ' /syntax ' (make sure you add square brackets around the 'syntax="Turing" and /syntax)
For example:
Turing:
%-% code here %-%
As for your game, try attaching the picture so that I can see what the problem is.
But as far as what I can make of it, try adding surfaces and make sure that you to do the collision checking for that in a different manner than that of the surface:
make sure that you can't jump upwards through the surface and that you stay on the surface when you land there
I don't have time so I can't help u much......sry bout that!
Mustiko
Posted: Sun Apr 13, 2008 6:17 pm Post subject: Re: Need help with AI and setting boundaries and collision detection
Well heres the code
Turing:
var MainWin :=Window.Open("graphics:800,600,offscreenonly") var key :arraycharofboolean var gravity, jumpheight, speed :int var posx, posy, velx, vely :real:=0 var onground :boolean
speed :=5
gravity :=2
jumpheight :=25
posx :=maxxdiv2
posy :=maxydiv2
onground :=false
and i attached the pictures now and i dont have platforms yet i just want the simple walking and jumping and standing still to work then im going to add the platforms so i can do one problem at a time heh....
also i have picture of him standing still left but i need to figure out how to make him stand stll to the left after he stops walkign leftbut ill attach the left picture if u guyz can figure out problem
thanks
still l.bmp
Description:
standing still left
Filesize:
1.53 KB
Viewed:
3938 Time(s)
standing still right.bmp
Description:
standing still right
Filesize:
1.37 KB
Viewed:
3938 Time(s)
moving left.bmp
Description:
moving left
Filesize:
1.53 KB
Viewed:
3938 Time(s)
moving right.bmp
Description:
moving right
Filesize:
1.81 KB
Viewed:
3938 Time(s)
Sean
Posted: Sun Apr 13, 2008 7:16 pm Post subject: Re: Need help with AI and setting boundaries and collision detection
For platforms, you are using distances and height for them. These are the platforms x and y variables, you will want to check if your character is between those x variables, and equal to the upper most y variable on the platform.
Here is what I mean if you did not get my first section..
Turing:
%This is a made up platform Draw.Box(x ,y , x2, y2, black)
You will want to check to see if your character is between the x and x2, that being the x position of the player, against the x and x2 positions of the platform. Also, you will want to check if the characters y position to see if it is equal to the y2 of the platform, if it isn't he is not on the platform.
A.J
Posted: Sun Apr 13, 2008 8:47 pm Post subject: Re: Need help with AI and setting boundaries and collision detection
when mario is moving, make sure he isn't 'gliding' by alternating between the still and moving pictures every frame.
for doing that, change:
by adding a variable 'count=0' outside the loop and increasing it by one everytime at the beginning of the loop.
to make sure it never exceeds maxint, then just add the following to the end of your loop:
Turing:
if count>1000then
count=1 endif
I hope this helped
Mustiko
Posted: Mon Apr 14, 2008 8:48 am Post subject: Re: Need help with AI and setting boundaries and collision detection
Thanks for your help and is count an interger or real or wat srry im pretty noob and at the beginining of the loop do i do count +1 or wat again im pretty noob....
Sponsor Sponsor
Mustiko
Posted: Mon Apr 14, 2008 9:05 am Post subject: Re: Need help with AI and setting boundaries and collision detection
actually im stupid lol i figured it out anyway but now you no how i had the code:
well that code whenever he walks he faces right when he stops even if he was walking left
i wonder if i should change it or not please check and see if it looks fine and doesnt matter or if theres a simple solution then ill take it thks
Mustiko
Posted: Mon Apr 14, 2008 4:39 pm Post subject: Re: Need help with AI and setting boundaries and collision detection
I have a question again well I asked this before but do any of you have links to the stuff I need like right now I am using watdotcolor collision detection and there somethign better yet i cant find it so if theres a link please post it and also i still need AI so if you guyz could tell me where i could get the code to make enemies walk back and forth and kill the character when he touches them unless he lands on the top of them then they die. Thanks
OneOffDriveByPoster
Posted: Mon Apr 14, 2008 5:32 pm Post subject: Re: Need help with AI and setting boundaries and collision detection
Mustiko @ Mon Apr 14, 2008 4:39 pm wrote:
right now I am using watdotcolor collision detection and there somethign better yet i cant find it
I think that should be good enough, and probably gives you the best accuracy since you are using actual pictures.
Quote:
need AI so if you guyz could tell me where i could get the code
We can't tell you where to get the code. I know some people who just copy random things off the Internet and pastes them together...
Mustiko
Posted: Mon Apr 14, 2008 6:48 pm Post subject: Re: Need help with AI and setting boundaries and collision detection
When I mean get the code i meant like a tutorial or something with examples and maybe for the type of AI i need or if you no how to make wat i need then please if you could possibly tell me wat i need to do or where I can find how to do it
Sean
Posted: Mon Apr 14, 2008 7:28 pm Post subject: Re: Need help with AI and setting boundaries and collision detection
For AI, you will want a person to follow you, and attempt to get to you. This is another character, built in with variables like your character.
You will be moving around with your variables, your player_x, and player_y variables. Your AI should be attempting to equal them, if they don't equal the x and y position then you either need to increase x , or y, or decrease them.
Turing:
%A sample if statement
if AI_X > player_x then
AI_X -=1 endif
That is all I will give, it should give you the basic knowledge to do other ones. So, what that if statement does is check to see if the AI is greater then the Player's X position and tries to equal it.
You should be able to do rest now, with that basic understanding, any further questions feel free to ask.
Mustiko
Posted: Tue Apr 15, 2008 9:49 am Post subject: Re: Need help with AI and setting boundaries and collision detection
Ok thanks but my question is when the enemy with AI tries to equal my characters position will there be any glitches such as in my char is above the enemy and the enemy is below will he suddenly fly up....o wait i think i answered that my self cuz hes equaling the players x value only, not the y value....I see and so if I define 2 walls though and the enemy is startign somewhere he will walk toward my character but is there a way to tell it to walk toward my character only if he comes near and if he isnt near walk bak and forth
Mustiko
Posted: Tue Apr 15, 2008 10:27 am Post subject: Re: Need help with AI and setting boundaries and collision detection
may I ask wat is wrong the character cannot jump wen on the platform and when i change soemthing he goes through or blah balh i asked my friend but he needs soem time cuz hes pretty busy anyone ahve any ideas....
Heres the code:
Turing:
var MainWin :=Window.Open("graphics:800,600,offscreenonly,nocursor,title:Mario") var key :arraycharofboolean var gravity, jumpheight, speed :int var posx, posy :int var velx, vely :real:=0 var onground :boolean var count :int:=0 var colcheck, groundcol :int:=7 var collision :boolean:=true const ground :=100
speed :=5
gravity :=2
jumpheight :=25
posx :=maxxdiv2
posy :=maxydiv2
onground :=false