• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Rotating Cog Collision?

Conbeef

Member
How do I go about making a rotating cog similar to the one in new super mario bros wii u. For the pass couple of days its been killing me. Have anyone done this before? If so, how do I go about doing it with collisions?
 
N

Never Mind

Guest
This seems like a good time to use a "precise collision checking" mask.
Perhaps switch the cog instances mask sprite to empty when the player is not within a certain distance range.

As for applying the spinning movement to the player when he's standing on it.. look into:
lengthdir_x / lengthdir_y
You can use point_distance / point_direction to find the offset from the cog's center to the player.
Then if you plug that information into those functions, and add the cogs angular speed to the "dir" argument, you could find new coordinates for the player.
 
Last edited by a moderator:

GMWolf

aka fel666
In the cog creation code, simply add multipliers so they will turn by some amount of the input rotation

You will have to manually calculate the gear ratios but that way you don't have to deal with collisions, and you end up with a more accurate, stable and efficient system anyways.
 

DesArts

Member
One rotating cog, or a few that connect?

Either way, as stated above, a system which simulates the effect of a cog(s) without actually using real complicated cog collision would work much better.
 

Conbeef

Member
One rotating cog, or a few that connect?

Either way, as stated above, a system which simulates the effect of a cog(s) without actually using real complicated cog collision would work much better.
one rotating cog that the player will be able to stand on or get pushed off etc...
 
N

Never Mind

Guest
I believe these other suggestions aren't actually about what your trying to do.
I mean yes, you could separate the teeth from the circle portion, and perhaps that would allow to avoid precise collision checking... but
Look at that picture.
Do your suggestions have any implications that I didn't already cover for this type of thing?
I don't think he's trying to have connected gears with different sizes, teeth count, etc.

You could always avoid using a collision mask and just use data / math to calculate collisions.
However, I was thinking this is actually a pretty good time to use a precise mask (and switch to no mask when player's not near to optimize as I suggested). Would you agree?
 

Conbeef

Member
I believe these other suggestions aren't actually about what your trying to do.
I mean yes, you could separate the teeth from the circle portion, and perhaps that would allow to avoid precise collision checking... but

Look at that picture.
Do your suggestions have any implications that I didn't already cover for this type of thing?
I don't think he's trying to have connected gears with different sizes, teeth count, etc.

You could always avoid using a collision mask and just use data / math to calculate collisions.
However, I was thinking this is actually a pretty good time to use a precise mask (and switch to no mask when player's not near to optimize as I suggested). Would you agree?
Yes thats what I meant. I will try your suggestion when I get home. Thumbs up

I'll update you if it works
 
N

Never Mind

Guest
Yeah, now that I think about it..
There's a huge difference between just detecting the collision, and handling it nicely within your character controller.

I might try to see if I can get anything working with a simple project soon, but in general it's pretty hard to get players to react nicely with moving objects and angled surfaces.. especially when there's gravity involved.

As I'm sure you know, it's pretty easy to make it so players can't tunnel into walls that don't move, but once you have two moving objects it becomes a task of separating them (even if the player isn't trying to move himself).
We know the cog isn't going to react to the player, so that makes it a little easier.

The idea behind separating them is to find or calculate the path of least resistance, while also taking movement forces into account.

I'll be back soon.
Sorry
I gave you some of the pieces, but this is a pretty hard puzzle to put together.. it also somewhat depends on how you're currently handling collisions.
 

DesArts

Member
Scale also comes into play. If you are working with a scale more akin to 8 bit games (very small) you can get away with far more tricks than you can at higher resolutions.

I can think of an method which only allows you to stand on an outer circle at certain angles, and if not, you fall into a smaller circle, and while on that smaller circle you cannot move further than a few degrees. But something this 'cheap' would only work at small resolutions, and you wouldn't be able to stand on the gear spikes. However you could add temporary flat solids as the gears go round the sides to combat this. It's all an approximation.
 
Last edited:
N

Never Mind

Guest
Desix is totally right.

Collision with a platonic shape is much different than one that's 32 pixels wide.

With that new perspective, I came up with a work around (everything's a work around right?).
There is still much to be done.
I basically just decided to use a grid of non-rotating blocks to simulate a larger rotating body. Collisions with non-rotating platforms is pretty straight forward. You might even have some in your game already!
I'll post back with details later.

Hopefully this gets you thinking in a direction that will work for you. The project file I made is really messy right now and desperately needs optimization.
It might take some more work to get things looking smoother / less ugly.

-------------------
That's just one method.

In the end, the smoothest / most optimized way of doing it would probably be to treat the teeth as separate from the inner circle.

You could create and test the rotating platform separately from the inner circle collision and mess with them until you get each to a place you like.
 
Last edited by a moderator:

DesArts

Member
That's just one method.

In the end, the smoothest / most optimized way of doing it would probably be to treat the teeth as separate from the inner circle.

You could create and test the rotating platform separately from the inner circle collision and mess with them until you get each to a place you like.
This one's definitely better, there's a lot of potential of lag and error with the many tiny blocks. All you'd need is some set up regarding moving/rotating platforms.
In any situation it's best to do something mathematically rather than using pixel masks (for example, the player snapping into position because it's already known, rather than looping through each pixel looking for an approximately correct spot). So any method's effectiveness depends how your platform engine is set up.
 
N

Never Mind

Guest
Desix
I do agree, especially when it comes to performance.
But we do need to take into account the fact that the tiny blocks are just a group of many smaller (basically math based) collision shapes compounded together.
The pixel mask is only being used for reference.


Conbeef
I've never tried to do platform physics with rotating blocks.. It seems extremely dependent on how the player physics is set up to begin with.
It would probably be best to start with some simple static slopes and figure out how the player should react to those.
For instance, the way N-game handles slopes is going to be much different than a Mario games:
upload_2017-4-21_18-45-23.png

I'll upload the project file for that other one for you to look at, but I advise against using it.
 
Last edited by a moderator:

Conbeef

Member
I've been playing around a bit and got something to work....finally! lol. It's not perfect though biut it will have to do for now. @Never Mind I still would like to see that example of yours.

Here's the code I have now :
Code:
if(place_meeting(x,y-1,obj_player)){
    with(instance_place(x,y-1,obj_player)){
        var _p1x = x;
        var _p1y = y;
        var l=point_distance(other.x,other.y,_p1x,_p1y);
        var d = point_direction(other.x,other.y,_p1x,_p1y)+other.rotSpd;
        x = other.x + lengthdir_x(l,d);
        y = other.y + lengthdir_y(l,d);
        while(place_meeting(x, y, other)){
            x += lengthdir_x(1,d);
            y += lengthdir_y(1,d);
        }
    }
}
I'll make a lil clip of it in a bit.

Edit: Also, I have a slope script that works perfectly. You'll see in the clip when I upload it
 
Top