F***ing AI!!!

Posted by Onyx on Oct. 12, 2006, 4:11 a.m.

This script is driving me crazy!!! I can't find what's wrong with it. It's supposed to find a nearest corner it comes by but for some reason it goes too far!

obj_enemy

//create event

direction=270
speed=1
i=1

//collision event with obj_solid
speed=0

col_dir=direction

cos1=round(cos(degtorad(col_dir+90)))
cos2=round(cos(degtorad(col_dir)))
sin1=round(-sin(degtorad(col_dir+90)))
sin2=round(-sin(degtorad(col_dir)))
point[0,0]=x+sin1
point[0,1]=y+cos1
cor=false

while(cor=false)
{
	checkx=point[0,0]+i*cos1+cos2
	checky=point[0,1]+i*sin1+sin2

	if !place_meeting(checkx,checky,obj_solid)
	{
		point[1,0]=checkx
		point[1,1]=checky
		cor=true
	}
      i+=1
}

show_message(string(point[1,0])+", "+string(point[1,1]))

Can anyone find what's wrong with it?

Comments

Evilish 18 years, 2 months ago

Nearest corner… wait, what do you mean by that?

I made alot of nearest [insert thing here] scripts… could talk to you about the general way it's done…

Maxcore 18 years, 2 months ago

Why are you doing trig? Just get the room height and width

see where you are

then each corner would have a range.

ParadoxEquation 18 years, 2 months ago

Nearest corner like in stucking your back on wall like on Counterstrike? Is that what you mean?

Please be more specific and it would be really good if you have a screenshot here to pinpoint the problem.

frenchcon1 18 years, 2 months ago

what does nearest corner mean?

noshenim 18 years, 2 months ago

maybe changing

Quote:
point[0,0]=x+sin1

point[0,1]=y+cos1
to
point[0,0]=x+cos1

point[0,1]=y+sin1
!??

still, nearest corner?