Go to page Previous  1 ... 7, 8, 9, 10, 11, 12  Next  [ 231 posts ]  Reply to topicPost new topic 
Author Message
 [gb]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Mon Feb 17, 2014 8:41 pm 
I never really was on your side.
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
Name: Smooth circular collision detection
Program: All versions of GameMaker (I think)
User: Im the Red Spy
Registered: I don't think so.

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
//By Im the Red Spy
//execute this script via: scr_collision(object being collided with, radius of collision) or whatever you decide to name it. eg (collide(oSolid,16))
//This can be put in either a collision event or the step event. Works best in a step event.
var object, radius; //object
object=argument0;
radius=argument1
for(col=0;col<360;col+=20) //A for loop checks for every direction that is a multiple of 20 (0, 20, 40...etc)
//20 can be changed to higher numbers (faster but probably less efficient) or lower numbers (slower but more precise)
    {
    while(position_meeting(x+lengthdir_x(radius,col),y+lengthdir_y(radius,col),object)) //checks for the object colliding at a spot around the circle for which radius defines
        {
        x-=lengthdir_x(.2,col); //move the object back according to the direction (col)
        y+=lengthdir_y(.2,col); //move the object back according to the direction (col)
        }
    }


Last edited by Im the Red Spy on Mon Feb 17, 2014 10:23 pm, edited 1 time in total.
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Mon Feb 17, 2014 9:23 pm 
User avatar
Lawful Evil
Member
[*]
[*]
[*]
[*]
[*]

[*]
I don't understand the intention of the above code. For determining if two circular regions are colliding, just see if the distance between their centers is smaller than their combined radii. If object1 has a radius r1 and object2 has a radius r2,

return (point_distance(object1.x,object1.y,object2.x,object2.y) < r1+r2)

If you want this object to move away from the other object until it no longer collides, simply do (in this example)

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
intersectingDistance = point_distance(object1.x,object1.y,object2.x,object2.y) - (r1+r2)
if (intersectingDistance <= 0)
 return false;
angle = degtorad(point_direction(object1.x,object1.y,object2.x,object2.y))

x -= cos(angle)*intersectingDistance
y -= sin(angle)*intersectingDistance

return true;

No looping required.

Furthermore, why are you inconsistent with how you determine x and y components of vectors? In the while loop, you use lengthdir_x() and lengthdir_y() to find the vector (which does not require converting to radians) yet you use cos() and sin() to determine the vectors when moving back... x -= lengthdir_x(0.2,col) and y -= lengthdir_y(0.2,col) would've done the same thing with far fewer operations and less conversion gobbledygook. And degtorad is a far better way to convert degrees to radians than multiplying by pi/180, as the function takes into account how radians (in Game Maker) go clockwise, rather than counterclockwise as with degrees.

...And while I'm at it, here's a more legible version of my previous moving-closer-to-another-angle script:

Name: moveToAngle(startDirection,goalDirection)
Program: GameMaker 8.0 (Should be fine in later versions, too)
User: Magnemania
Registered: No

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
//argument0: current direction
//argument1: direction to face

compareDirection = argument1;
compareDirection -= argument0;

if (compareDirection < 0)
   compareDirection = 360+compareDirection;

if (compareDirection > 180)
    plusMinus = -1;
else
    plusMinus = 1;

return plusMinus;

_________________
Image
Magikoopa Security Force, the Mario Action-Strategy game!
  It's time to fight for Bowser!
 
Top
Offline 
 User page at mfgg.net
 
 [gb]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Mon Feb 17, 2014 10:23 pm 
I never really was on your side.
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
Maybe its just my interpretation of your post but it sounded a lot more harsh than it should have. Also, its not for two circular regions. just a circular object (for example, a player) colliding with an object (for example, a wall, or any type of solid). Ill fix my inconsistencies though

 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Mon Feb 17, 2014 10:42 pm 
User avatar
Lawful Evil
Member
[*]
[*]
[*]
[*]
[*]

[*]
Im the Red Spy wrote:
Maybe its just my interpretation of your post but it sounded a lot more harsh than it should have.


My apologies, I suppose my suggestions may have come off as a bit too aggressive.

Quote:
Also, its not for two circular regions. just a circular object (for example, a player) colliding with an object (for example, a wall, or any type of solid).


Hmm...I can't immediately think of any better solutions, but I think that there might be a better way to go about this. The way the angles are currently determined gives a bias towards moving in a circular fashion; if I were, say, moving up into a rectangular wall and I was using this method to avoiding colliding with it, I would end up sliding to the left, as (unless I was moving a single pixel at a time and 90 would be one of the values col becomes) I would detect the wall between 90 and 80 degrees or so, and the circular object would get pushed down and slightly to the left. While this would probably be a small amount, this could eventually result in quite a lot of leftward movement over time. It's a bit imprecise.

_________________
Image
Magikoopa Security Force, the Mario Action-Strategy game!
  It's time to fight for Bowser!
 
Top
Offline 
 User page at mfgg.net
 
 [gb]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Mon Feb 17, 2014 11:14 pm 
I never really was on your side.
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
I believe the issue could be fixed by selecting a factor of 90, such as 15. Honestly, the code I made is imperfect. I'm still trying to find ways to make it better. It works speedwise and it does what I want it to, but it can be slightly jittery at times. Its not noticable in 2d, but in a 3d game I'm working on, the collisions can appear to shake back and forth. All i can do is lather rinse and repeat

 
Top
Offline 
 User page at mfgg.net
 
 [es]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Sun Mar 02, 2014 10:27 am 
User avatar
I'm just a little adorable kitty :3
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

Making enemies respawn at the start position

1.- Create an object with these variables on it.

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
move = 0;
respx = xstart; //Set the 'x' position where the enemy will respawn.
respy = ystart; //Set the 'y' position where the enemy will respawn.
respobj = object_index; //Sets the object that will appear after respawning. (I recommend using the name of the original object.)


2.- Add this code on 1 of the step events of the object.

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
if (move == 0) {
    if (x > view_xview[0]-32)
    && (y > view_yview[0]-32)
    && (x < view_xview[0]+458)
    && (y < view_yview[0]+272) {
        move = 1;
        //Add here some movement code and make sure 'move = 1' is present on the code, otherwise it will not work.
    }
}
else if (move == 1) {
    if (x < view_xview[0]-32)
    || (y < view_yview[0]-32)
    || (x > view_xview[0]+458)
    || (y > view_yview[0]+272) {
        move = 2;
        instance_destroy();
        respawn = instance_create(respx,respy,obj_enemy_respawn)
            respawn.npc = respobj;
    }
    //Add here the movement code.
}


3.- Create a new object and add this code on the step event.
Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
if (x < view_xview[0]-32)
|| (y < view_yview[0]-32)
|| (x > view_xview[0]+458)
|| (y > view_yview[0]+272) {
    instance_create(xstart,ystart,npc);
    instance_destroy();
}


4.- If you want to make the original enemy appear on the start position, do this.
Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
enemy = instance_create(x,y,obj_enemy)
with (enemy) {
    move = 1;
    respx = respx;
    respy = respy;
    respobj = respobj;
}


Follow these steps and voila, your enemy objects will respawn on the start position :)

_________________
Image ImageImageImageImageImageImage Image
~ Supernova / Drawerkirby (2) / Gato / Neweegee (2) (3) ~
"shy guys are wall plugs confirmed" - Vitiman on Club Saturn Ex
Image
 
Top
Offline 
 User page at mfgg.net
 
 [vn]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Mon Mar 03, 2014 12:26 am 
User avatar
Member
Is OSMBE2 download link fixed?

 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Tue Mar 04, 2014 10:06 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
Tiled Backgrounds w/ Movement

Want to have a moving background that is tiled throughout a room, throughout an entire level, and have full control over its movement and speed? Here is an example just for that.

The example below is for vertical tiling. I've yet to try both horizontal and vertical at the same time, however. It should still work.

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
// In the Create Event of an object designated for backgrounds
step_vert = 0;
spd = 1;    // speed of the moving background
bg = background
 

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
// In the End Step Event of an object designate for backgrounds
step_vert += spd;
if (step_vert > background_get_height(bg) step_vert = -background_get_height(bg);
 

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
// In the Draw Event of an object designated for backgrounds
for (i=-background_get_height(bg) + step_vert; i < room_height; i += background_get_height(bg)) {
    draw_background(bg,view_xview[0],view_yview[0],i);
}
 

 
Top
Offline 
 
 
 [gb]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Tue Mar 04, 2014 11:31 pm 
I never really was on your side.
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
Is there any benefit in using that as opposed to background_hspeed[0...] and background_vspeed[0...]?

 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Wed Mar 05, 2014 6:53 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
I'm currently unaware of any right now. I made this because I forgot game maker actually had a method for doing it. :P

I guess if you had more than 8 backgrounds then this could be helpful. Seeing as game maker only allows their assigned methods to hold [0-7].

 
Top
Offline 
 
 
 [es]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Sun Mar 09, 2014 4:45 pm 
User avatar
I'm just a little adorable kitty :3
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

@kremling: I added your tutorial on the first post, it took long because I was kinda busy.

_________________
Image ImageImageImageImageImageImage Image
~ Supernova / Drawerkirby (2) / Gato / Neweegee (2) (3) ~
"shy guys are wall plugs confirmed" - Vitiman on Club Saturn Ex
Image
 
Top
Offline 
 User page at mfgg.net
 
 [vn]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Fri Mar 14, 2014 10:14 am 
User avatar
Member
Sorry to ask,but when will u fixed the OSMBE2 link?

 
Top
Offline 
 User page at mfgg.net
 
 [es]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Fri Mar 14, 2014 10:49 am 
User avatar
I'm just a little adorable kitty :3
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

SunRaiZ wrote:
Sorry to ask,but when will u fixed the OSMBE2 link?


It works for me.

_________________
Image ImageImageImageImageImageImage Image
~ Supernova / Drawerkirby (2) / Gato / Neweegee (2) (3) ~
"shy guys are wall plugs confirmed" - Vitiman on Club Saturn Ex
Image
 
Top
Offline 
 User page at mfgg.net
 
 [vn]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Sat Mar 15, 2014 7:30 am 
User avatar
Member
But it's broken,right?

 
Top
Offline 
 User page at mfgg.net
 
 [es]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Sat Mar 15, 2014 8:00 am 
User avatar
I'm just a little adorable kitty :3
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

SunRaiZ wrote:
But it's broken,right?


Nope

_________________
Image ImageImageImageImageImageImage Image
~ Supernova / Drawerkirby (2) / Gato / Neweegee (2) (3) ~
"shy guys are wall plugs confirmed" - Vitiman on Club Saturn Ex
Image
 
Top
Offline 
 User page at mfgg.net
 
 [cn]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Sat Mar 15, 2014 9:37 am 
User avatar
Dang ol Roushi I tell you what
Site Staff
[S]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

SunRaiZ wrote:
But it's broken,right?

I think that file hosting website might be block by Vietnamese Government. You might need to ask someone nicely to transfer a file via email or something.

_________________
 
Top
Offline 
 User page at mfgg.net
 
 [vn]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Sat Mar 15, 2014 10:20 am 
User avatar
Member
Can you upload it on Mediafire?

 
Top
Offline 
 User page at mfgg.net
 
 [tr]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Sat Mar 15, 2014 12:39 pm 
User avatar
Thanks DonnieTheGuy!
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

2shared is blocked on my country too. BUT I USE DNS! (evil laugh)
http://www44.zippyshare.com/v/99243062/file.html

_________________
Image
 
Top
Offline 
 
 
 [es]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Sat Mar 15, 2014 12:46 pm 
User avatar
I'm just a little adorable kitty :3
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

Mors wrote:
2shared is blocked on my country too. BUT I USE DNS! (evil laugh)
http://www44.zippyshare.com/v/99243062/file.html


Mors, I already added a mirror on the first post.

_________________
Image ImageImageImageImageImageImage Image
~ Supernova / Drawerkirby (2) / Gato / Neweegee (2) (3) ~
"shy guys are wall plugs confirmed" - Vitiman on Club Saturn Ex
Image
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Engine / Tutorial Topic
PostPosted: Sat Mar 15, 2014 1:00 pm 
User avatar
もう帰らない
Member
[*]
[*]
[*]
[*]
Mors wrote:
2shared is blocked on my country too. BUT I USE DNS! (evil laugh)

Uh... what? I use the domain name system too, but I don't get what it has to do with censorship...

One way to get past censorship of the Internet, by the way, is Tor:

https://www.torproject.org/projects/torbrowser.html.en

_________________
https://onpon4.github.io
 
Top
Offline 
 
 
« Previous topic | Next topic »
Display posts from previous:  Sort by  
Go to page Previous  1 ... 7, 8, 9, 10, 11, 12  Next  [ 231 posts ]  Reply to topicPost new topic 


Who is online

Users browsing this topic: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group