I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: Junior Nintendista on September 13, 2015, 10:51:07 AM

Title: Handle rotary object
Post by: Junior Nintendista on September 13, 2015, 10:51:07 AM
I was wondering how to make a sucker for the background, for example, I put stars as an object and put a put another object in the center to suck, but the stars are turning to this subject in the center (like a black hole). How to do this?
Title: Re: Handle rotary object
Post by: lawatson on September 13, 2015, 11:42:26 AM
in the object getting sucked in, put this in the create event:

direction=point_direction(x,y,blackhole.x,blackhole.y);
speed=(maximum speed you want) / (maximum distance from the object) * point_distance(x,y,blackhole.x,blackhole.y);

step event code:

speed=(maximum speed you want) / (maximum distance from the object) * point_distance(x,y,blackhole.x,blackhole.y);
if point_distance(x,y,blackhole.x,blackhole.y)<speed{instance_destroy();}

If you want it to lose alpha as it approaches the object, put this in the step event too:

image_alpha=1-(1/(maximum distance from the object)*point_distance(x,y,blackhole.x,blackhole.y));

If you want it to get rotated inward, I have a way of doing that as well.
Title: Re: Handle rotary object
Post by: Junior Nintendista on September 13, 2015, 12:24:43 PM
in the object getting sucked in, put this in the create event:

direction=point_direction(x,y,blackhole.x,blackhole.y);
speed=(maximum speed you want) / (maximum distance from the object) * point_distance(x,y,blackhole.x,blackhole.y);

step event code:

speed=(maximum speed you want) / (maximum distance from the object) * point_distance(x,y,blackhole.x,blackhole.y);
if point_distance(x,y,blackhole.x,blackhole.y)<speed{instance_destroy();}

If you want it to lose alpha as it approaches the object, put this in the step event too:

image_alpha=1-(1/(maximum distance from the object)*point_distance(x,y,blackhole.x,blackhole.y));

If you want it to get rotated inward, I have a way of doing that as well.
Yes, I want it turning, but also want the stars randomly create the room from anywhere.
Title: Re: Handle rotary object
Post by: Junior Nintendista on September 13, 2015, 02:02:26 PM
This may explain more or less in the center is the object and the stars will be randomly created from anywhere in the room and will be sucked into these object with the star revolving movement.
(https://i.imgur.com/cVAvxRf.png)
Title: Re: Handle rotary object
Post by: infern0man1 on September 13, 2015, 02:08:40 PM
instance_create(random(800),random(608),objStar);
Title: Re: Handle rotary object
Post by: lawatson on September 13, 2015, 02:37:34 PM
Alright, I've got some tricks up my sleeve for that. I'll just modify the original message into this post.

in the object getting sucked in, put this in the create event:

radius=point_distance(x,y,blackhole.x,blackhole.y);
angle=point_direction(x,y,blackhole.x,blackhole.y);
speed=(maximum speed you want) / (maximum distance from the object) * point_distance(x,y,blackhole.x,blackhole.y);

step event code:

x=blackhole.x+(radius*cos(degtorad(angle)));
y=blackhole.y+(radius*-sin(degtorad(angle)));
angle+=(rotation speed here);
speed=(maximum speed you want) / (maximum distance from the object) * point_distance(x,y,blackhole.x,blackhole.y);
radius-=speed;
if point_distance(x,y,blackhole.x,blackhole.y)<speed{instance_destroy();}

If you want it to lose alpha as it approaches the object, put this in the step event too:

image_alpha=1-(1/(maximum distance from the object)*point_distance(x,y,blackhole.x,blackhole.y));

If you want it to lose rotation speed as it approaches the object, replace the angle+=(rotation speed here) code with:

angle+=(maximum speed you want) - ((maximum speed you want) / (maximum distance from the object) * point_distance(x,y,blackhole.x,blackhole.y));

That should be it. If there's a bug, post it.
Title: Re: Handle rotary object
Post by: Junior Nintendista on September 13, 2015, 06:05:59 PM
instance_create(random(800),random(608),objStar);
I do not want to create only one star, I want to appear several stars randomly by side to be sucked into the blackhole.
Title: Re: Handle rotary object
Post by: infern0man1 on September 13, 2015, 06:08:49 PM
//spawning object's create event
alarm[0]=1;

//spawning object's alarm 0 event
for(i=0;i<(number of objects you want spawned per alarm);i+=1){
  instance_create(random(800),random(608),star);
}
alarm[0]=(how frequently you want this to occur);
Title: Re: Handle rotary object
Post by: Junior Nintendista on September 13, 2015, 06:23:31 PM
//spawning object's create event
alarm[0]=1;

//spawning object's alarm 0 event
for(i=0;i<(number of objects you want spawned per alarm);i+=1){
  instance_create(random(800),random(608),star);
}
alarm[0]=(how frequently you want this to occur);
I will explain once again, it is to create the stars themselves endlessly, creating all the time without stopping.
Title: Re: Handle rotary object
Post by: Sudnep on September 13, 2015, 06:50:14 PM
That will create the star object infinitely though.
Title: Re: Handle rotary object
Post by: Junior Nintendista on September 13, 2015, 07:07:22 PM
That will create the star object infinitely though.
But not infinitely created, created just a few and then did not create more. I'm actually asking these questions because I'm doing the fucking I Wanna Call Me It in my medley.
Title: Re: Handle rotary object
Post by: infern0man1 on September 13, 2015, 07:26:20 PM
Do you not understand why I set alarm[0] in the alarm 0 event? That resets the alarm and the process happens again infinitely.
Title: Re: Handle rotary object
Post by: Junior Nintendista on September 13, 2015, 07:29:12 PM
Do you not understand why I set alarm[0] in the alarm 0 event? That resets the alarm and the process happens again infinitely.
Be more specific, it is very complicated, I am unable to understand.
Title: Re: Handle rotary object
Post by: infern0man1 on September 13, 2015, 07:32:05 PM
//spawning object's create event
alarm[0]=1; //sets the alarm at the start

//spawning object's alarm 0 event
for(i=0;i<(number of objects you want spawned per alarm);i+=1){ //10 stars are created per alarm
  instance_create(random(800),random(608),star);
}
alarm[0]=(how frequently you want this to occur); //alarm is reset and everything happens again

Title: Re: Handle rotary object
Post by: lawatson on September 13, 2015, 08:06:34 PM
>tfw

basically alarm events are activated when you set them, so alarm[0]=10 will make alarm 0 activate after 10 frames. if you set an alarm inside an alarm, you can make an infinite loop. Then you just put in the create star code and that should do it.
Title: Re: Handle rotary object
Post by: Junior Nintendista on September 13, 2015, 08:17:14 PM
>tfw

basically alarm events are activated when you set them, so alarm[0]=10 will make alarm 0 activate after 10 frames. if you set an alarm inside an alarm, you can make an infinite loop. Then you just put in the create star code and that should do it.
Another error, the speed of stars is absurd's very fast and not giving this to change.
Title: Re: Handle rotary object
Post by: Junior Nintendista on September 13, 2015, 08:20:25 PM
O_O

(https://i.imgur.com/qCVjIYi.png)
Title: Re: Handle rotary object
Post by: Archee on September 14, 2015, 02:14:09 AM
Try this: https://www.mediafire.com/download/7menx7w7soy8q4e/

Edit: updated, previous version was unfinished.
Title: Re: Handle rotary object
Post by: Junior Nintendista on September 14, 2015, 05:00:52 PM
Try this: https://www.mediafire.com/download/7menx7w7soy8q4e/

Edit: updated, previous version was unfinished.
It's almost that, but objects can only be constantly spinning on the screen.