Jump to content


Photo

spawnpoint issue


  • Please log in to reply
23 replies to this topic

#1 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 04 May 2012 - 06:05 PM

in an alarm[0] event, i want an object to test a 100width x 50height circle around a random location relative to a second object(-1000 to +1000 x,y, relative to obj_two), and if no collision with solid, create an instance of a 3rd object at that location, else {alarm[0] = 1 ; alarm[1] = +1 relative} how would i code that? (plz use obj_one obj_two obj_three, and var_rdx var_rdy)

obj_one is already set up to generate the random x y #s so those variables are attached to obj_one

d&d or gml solution would be fine. thank you.

Edited by Piwaket, 08 May 2012 - 12:13 AM.

  • 0

#2 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1489 posts
  • Version:GM:Studio

Posted 04 May 2012 - 06:19 PM

im not going to code it all for you but check out, place_free and place_empty in the help file. or alternatively collision_circle
  • 0

#3 Mr B

Mr B

    GMC Member

  • GMC Member
  • 172 posts

Posted 04 May 2012 - 06:21 PM

Is the alarm event in the first or second object?
  • 0

#4 Mr B

Mr B

    GMC Member

  • GMC Member
  • 172 posts

Posted 04 May 2012 - 06:25 PM

if !collision_ellipse(obj_two.x-var_rdx-50,obj_two.y-var_rdy-25,obj_two.x-var_rdx+50,obj_two.y-var_rdy+25,all,true,true).solid
or
if !collision_ellipse(x-obj_one.var_rdx-50,y-obj_one.var_rdy-25,x-obj_one.var_rdx+50,y-obj_one.var_rdy+25,all,true,true).solid

  • 0

#5 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 04 May 2012 - 06:30 PM

im not going to code it all for you but check out, place_free and place_empty in the help file. or alternatively collision_circle



thank you, i did look last night.....alot...googled a bunch and so on, i understand place_free sort of, but i dont really know how to code in gml ... my syntax is usually wrong somehow.

like:

if(collision_point(0+self.var_rdx,0+self.var_rdy,solids,true,false)) then instance_create (0+self.var_rdx,0+self.var_rdy,obj_three) else {self.alarm[1]+=1 self.alarm[0]=1}

thats what i came up with... and i checked "object" and selected obj_two...."solids" is a parent object to all solids in my game..... i just cant get it to work, its not for lack of TRYing.... i just dont know what im doing wrong.

and collision_circle was more confusing so i didnt even try messing with that, i couldnt get the easier way to work.

Edited by Piwaket, 04 May 2012 - 06:34 PM.

  • 0

#6 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 04 May 2012 - 06:44 PM

Is the alarm event in the first or second object?


the alarm is in the first object, the second object is the "spawn point" and the third object is the one i want to create


edit: i think i got it now, ill have to test. thank you Mr B!

edit edit: yes that worked perfectly, thank you again!

Edited by Piwaket, 04 May 2012 - 06:59 PM.

  • 0

#7 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 04 May 2012 - 10:12 PM

if !collision_ellipse(obj_two.x-var_rdx-50,obj_two.y-var_rdy-25,obj_two.x-var_rdx+50,obj_two.y-var_rdy+25,all,true,true).solid
or
if !collision_ellipse(x-obj_one.var_rdx-50,y-obj_one.var_rdy-25,x-obj_one.var_rdx+50,y-obj_one.var_rdy+25,all,true,true).solid



sorry for the double post but i had a related question, i understand how this code works all except the "!" .....what is the purpose of that?
  • 0

#8 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1489 posts
  • Version:GM:Studio

Posted 04 May 2012 - 11:06 PM

"!" means not

so
pie=5
if(pie!=3)
{
//the code would get to here
}

can be put infront of functions and all sorts
  • 0

#9 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 05 May 2012 - 12:47 AM

well i thought i understood that code but apparently i was a little overconfidant. i tried to manipulate it for another purpose and failed.

collision_ellipse(x-(var_range),y-(var_range),x+(var_range),y+(var_range),obj_monster,true,true)

im trying to detect a collision with obj_monster(parent object for all monsters in my game) at a variable range. that seeems like it should be right, any suggestions what i might be doing wrong would be apprecaited.

i realize it doesnt need to check itself for collisions but for my purposes it should be that way.


got it worked out.... i actually had it right but had other operations wrong.. anyway now im having another problem.

Edited by Piwaket, 05 May 2012 - 04:08 AM.

  • 0

#10 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1489 posts
  • Version:GM:Studio

Posted 05 May 2012 - 10:42 AM

anyway now im having another problem


and that is?
  • 0

#11 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 06 May 2012 - 06:31 PM


anyway now im having another problem


and that is?



if i understand it right direction can be 0-360 .....0 being x,y, relative(or the pixel you are starting from) im assuming...

anyway, i want to get a direction of an object(relative to self).... i know how to do that part, and then "jump to" one pixel in the opposite direction ... so if the other object is at say 12:00 the object checking would "jump to" one pixel in the direction of 6:00
i know i could move in the direction at -1 but i need it to be "jump to"

any semi-simple way to do this?

Edited by Piwaket, 06 May 2012 - 06:35 PM.

  • 0

#12 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1489 posts
  • Version:GM:Studio

Posted 06 May 2012 - 06:45 PM

direction can be >360 it keeps going round and round 360 being one loop

so store in each object a new direction variable called dir

if(point_distance(xprevious,yprevious,x,y))
{
dir=point_direction(xprevious,yprevious,x,y);//this will between 0 and 360
}

put that in step event, before you need to compare the 2 dir

or do it with math, which isnt fun(ive done it before as direction can be >360 or <0).


as for your jump to problem use:
xx=lengthdir_x(distance_to_move,dir_difference);
yy=lengthdir_y(distance_to_move,dir_difference);

Edited by Jack Indie Box, 06 May 2012 - 06:48 PM.

  • 0

#13 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 06 May 2012 - 06:55 PM

direction can be >360 it keeps going round and round 360 being one loop

so store in each object a new direction variable called dir

if(point_distance(xprevious,yprevious,x,y))
{
dir=point_direction(xprevious,yprevious,x,y);//this will between 0 and 360
}

put that in step event, before you need to compare the 2 dir

or do it with math, which isnt fun(ive done it before as direction can be >360 or <0).


as for your jump to problem use:
xx=lengthdir_x(distance_to_move,dir_difference);
yy=lengthdir_y(distance_to_move,dir_difference);


i think in my case the math would be pretty easy actually, dir=(point_direction(x,y,obj_other)+180)

knowing that it wraps makes that easy....ok i have my direction.... now how do i set a location x,y coordinate one pixel in that direction so that i can set "jump to" to that location?
  • 0

#14 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1489 posts
  • Version:GM:Studio

Posted 06 May 2012 - 07:13 PM

i already said xx=lengthdir_x(distance_to_move,dir_difference);
yy=lengthdir_y(distance_to_move,dir_difference);

and use jumpto with xx and yy

but im pretty sure you underestimate the math if you use direction(the built in variable)
  • 0

#15 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 06 May 2012 - 07:41 PM

unless im gravely mistaken no matter how many times you spin around, when you stop if you do a 180 you will be facing the other way.
(if theres some quirk in the direction function that makes it off a pixel or two thats fine, i was going to add in a randomizer of a few degree either way to direction anyway once i got the code figured out.)
what i was thinking would be:

var_dir = (point_direction(0,0,otherobject.x,otherobject.y)+180)

and that would give me my "opposite direction variable"

i guess i dont understand the code you are giving me, can you elaborate?

xx=lengthdir_x(distance_to_move,dir_difference);
yy=lengthdir_y(distance_to_move,dir_difference);

i understand that ure setting xx and yy so that you can then use that for jump to coordinates... distance_to_move would be 1 (for one pixel) and dir_difference would be the direction variable i want to go toward? .....and what is lengthdir_x and lengthdir_y?

im sorry im not that good with code but im trying. (and learning everyday!) :D

Edited by Piwaket, 06 May 2012 - 07:47 PM.

  • 0

#16 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1489 posts
  • Version:GM:Studio

Posted 06 May 2012 - 08:14 PM

lengthdir_x gets the x value of a a vector from the distance value(length, if negative would go backwards) based apon the direction value(the value after the ",")
y does the same but returns the y value(vector)

so just chuck in lengthdir_x(1,var_dir);
if var_dir is correct it will do what you want

please in future if you dont know how to use a new function(new to you), first go in the game maker help file, if your still confused use the game maker wiki, if still search the forum(people ask all the time, so you dont have to...) and if still stuck google is your friend and then lastly ask here

Edited by Jack Indie Box, 06 May 2012 - 08:15 PM.

  • 0

#17 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 06 May 2012 - 11:18 PM

the purpose of this whole mess was if the object executing the functions is touching/colliding with a solid, then "jump to" away from it one pixel at a time untill it was collision free. this was my understanding of how i should write that.(in a step event)
if collision_circle(0,0,50,solid,true,false)
{
if(point_distance(xprevious,yprevious,x,y))
{
dir=point_direction(xprevious,yprevious,x,y);//this will between 0 and 360
}

dir=dir+180

xx=lengthdir_x(1,dir);
yy=lengthdir_y(1,dir);
x=xx
y=yy
}
i then stacked my object(a solid with a 100x100 circle sprite with precice mask, that code, and a variable called dir set to 0) on top of another solid(also with variable dir just in case), ran it....and nothing happened.
did i code it wrong or missread what you ment? or am i going to need something else entirely?
  • 0

#18 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1489 posts
  • Version:GM:Studio

Posted 07 May 2012 - 08:54 AM

i thought you wanted:

i want to get a direction of an object(relative to self)

which i thought you meant, dir of one object compared to dir of player


also i dont think you can do a collision circle for all solids you are supposed to put a object or instance id. You shouldnt need to stack your object ontop of another, just have one object with all the code that you need. I am confused what you were trying to achieve again... explain and upload your file
  • 0

#19 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 07 May 2012 - 07:48 PM

i thought you wanted:

i want to get a direction of an object(relative to self)

which i thought you meant, dir of one object compared to dir of player


no, not exactly, in a step event(so its constantly checking.), i want object1 if touching a solid, to find the relative direction of that solid (the direction the solid is in relation to object1(both solid)) and if touching at all, i want object1 to "jump to" in the opposite direction of (away from) object2 one pixel. thats it.

if i cant run a blanket check for all solids i can make a parent "solids" object. so object1 couldnt include itself in the collision check(notme).

there really is no file, i gave an object that script and placed it on top another solid to test it, and it didnt seem to do anything (i didnt run it in debug mode since i barely understand code anyway, probably wouldnt do me much good.)
the purpose is that sometimes my solids spawn overlapping, which i want to happen but they stick together so i want them(in the event of an overlap) to seperate from eachother. i cant use bounce off solids or move to point_direction at - speed because it just results in a collision and goes nowhere. so i thought "jump to" might work because then it would jump, collision or not.

if collision with solid, get a direction, add 180 degrees, then jump one pixel in that direction. then if i could get that to work, from there i could add in something like if the two objects share the exact same location object1 could jump randomly to ( x -1 to +1, y -1 to +1) ...that part i could figure out im pretty sure.

Edited by Piwaket, 07 May 2012 - 08:19 PM.

  • 0

#20 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1489 posts
  • Version:GM:Studio

Posted 07 May 2012 - 08:57 PM

or you could just use place_free place_empty or i dono place_meeting(might work... could use "all" as the object dono) before you spawn the objects... im not sure why you want 2 solids to spawn overlapping then either change the spawn point or jump the object to a near free spot using the same function
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users