It is currently Wed May 23, 2018 7:21 pm

All times are UTC - 7 hours



Forum rules


Related:



Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Rotating room collision.
PostPosted: Sat Apr 28, 2018 1:56 pm 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2648
Does anybody know how collision was done in rotating rooms in games? I was thinking about doing a transform on the character's coordinates first, run the collision, then do the reverse transform, but I realized that doing two transforms will ruin precision. So I would need to save the "screen space" coordinates in case the character doesn't collide. There is still a problem with that. Sloped tiles have no effect on x velocity under normal circumstances, whereas doing collision inside a rotating play field would. Would I just ignore this little physics inconsistency between a sloped tile on a flat play field and a flat tile on a sloped playfield?


Last edited by psycopathicteen on Sat Apr 28, 2018 7:16 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sat Apr 28, 2018 3:41 pm 
Offline

Joined: Thu Feb 07, 2013 1:15 am
Posts: 115
Location: Sweden
psycopathicteen wrote:
Does anybody know how collision was done in rotating rooms in games? I was thinking about doing a transform on the character's coordinates first, run the collision, then do the reverse transform, but I realized that doing two transforms will ruin precision. So I would need to save the "screen space" coordinates in case the character doesn't collide. There is still a problem with that. Sloped tiles have no effect on x velocity under normal circumstances, whereas doing collision inside a rotating play field would. Would I just ignore this little physics inconsistency between a sloped play field and non sloped play field?

How about doing everything in non-rotated space and apply the rotation as a final “camera effect”, so to speak. Then the only thing that would need to be rotated on the game logic side of things is the gravity vector...


Top
 Profile  
 
PostPosted: Sat Apr 28, 2018 6:59 pm 
Online
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3316
Location: Nacogdoches, Texas
Not to mention that your character's hit box will not match the character's visual representation at all...


Top
 Profile  
 
PostPosted: Sat Apr 28, 2018 7:56 pm 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2648
Espozo wrote:
Not to mention that your character's hit box will not match the character's visual representation at all...


Yeah, I'd need to somehow switch vertical and horizontal collision around when it hits a certain place.

I have an idea. I already keep an old copy of x and y positions so that the collision routine knows where the object came from. I can use that information to recalculate the objects movement before applying collision, and then calculate screen coordinates. I would need to make the object slots slightly bigger again.

I might just implement a rotating platform before I tackle doing an entire rotating room, since my next boss fight will involve a rotating platform, and I haven't even gotten to drawing the giant robot yet.


Last edited by psycopathicteen on Sat Apr 28, 2018 9:01 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sat Apr 28, 2018 8:43 pm 
Online
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3316
Location: Nacogdoches, Texas
Yeah, moving the coordinates of everything around a certain point seems like the best solution, but introduces plenty of other problems. Does anyone have any idea how 3D games do collision? It's probably totally irrelevant to this though, because they have something just a bit more powerful than an approximately 3MHz 65816...


Top
 Profile  
 
PostPosted: Sat Apr 28, 2018 11:47 pm 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 426
Espozo wrote:
Yeah, moving the coordinates of everything around a certain point seems like the best solution, but introduces plenty of other problems. Does anyone have any idea how 3D games do collision? It's probably totally irrelevant to this though, because they have something just a bit more powerful than an approximately 3MHz 65816...


Always collide in World Space, and just move the camera to create local space. Very rarely does one collide in Screen space.


psycopathicteen - is this a mode 7 rotation?


Top
 Profile  
 
PostPosted: Sat Apr 28, 2018 11:52 pm 
Offline

Joined: Tue Oct 06, 2015 10:16 am
Posts: 731
3d collision is always in 3d space, so orientation is irrelevant. The basic unit is a ray, a line from this point to that point. Does it hit anything?
Then forms like boxes, spheres and ellipses are done on top, or with inner magic.

If you mean which way transformations go, everything is in world space. If the player's box gets rotated, then it gets rotated, but the world doesn't.


Top
 Profile  
 
PostPosted: Sun Apr 29, 2018 12:55 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6291
Location: Canada
The backbone of 3D is the matrix transform, which includes arbitrary rotation, among other transformations. Actually this matrix can contain a whole chain of them baked into a single matrix with an interesting trick.

It's predicated on being able to multiply, though. That's the big bottleneck for older systems like this, I think.

You can do all the same transformations in 2D, just with a matrix that's one column/row smaller (or ignored, as is usually the case with using modern hardware already built around 3D support).

If all you need is a rotation though, the basic unit of work is 4 multiplies and 2 adds per X,Y coordinate. If you're talking SNES, your mode 7 background is already doing this inherently for your background, and you just need to do that transform for your sprites. (Like others said, collision is done before the transform, the transform is just a "camera" thing.)


Top
 Profile  
 
PostPosted: Sun Apr 29, 2018 3:23 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7432
Location: Chexbres, VD, Switzerland
rainwarrior wrote:
It's predicated on being able to multiply, though. That's the big bottleneck for older systems like this, I think.

Probably why in Super Castlevenia IV there's no ennemies while the room is rotating, only when it's at 90° angle, so only the player's coordinates have to be transformed against the background.

Super Mario Kart had to use the DSP-1 in order to do a lot of multiply operations per frame.


Top
 Profile  
 
PostPosted: Sun Apr 29, 2018 5:26 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6291
Location: Canada
Well, there's workarounds, too. Like if you had a bunch of things on a grid you can rotate an offset vector once and just reuse that between items in the grid. Or you could have enemies confined to concentric circles, etc.

Contra III seems to have quite a few moving objects during its top-down freely rotating segments, and I don't think it had any add-on chips?


Top
 Profile  
 
PostPosted: Sun Apr 29, 2018 6:13 am 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2648
I came up with a math equation to eject objects straight vertically and horizontally so that the physics work the same both ways.

X = Ax + By
Y = Cx + Dy

popping y:
(Y - Cx)/D = y

popping x:
(X - By)/A = x

I haven't figured out how to do slopes while rotated though.


Top
 Profile  
 
PostPosted: Sun Apr 29, 2018 6:42 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20064
Location: NE Indiana, USA (NTSC)
Circle collision is circle collision no matter how much the circles are rotated. And it needs zero multiplies if you have a suitable lookup table or the objects' radii are suitably constrained.

Code:
xdistance = abs(x[oneobjid] - x[otherobjid])
ydistance = abs(y[oneobjid] - y[otherobjid])
sum_of_radii = type_to_radius[obj_type[oneobjid]] + type_to_radius[obj_type[otherobjid]]
if (xdistance < sum_of_radii
      and ydistance < sum_of_radii
      and squared[xdistance] + squared[ydistance] < squared[sum_of_radii]):
    log_collision(oneobjid, otherobjid)


Top
 Profile  
 
PostPosted: Sun Apr 29, 2018 6:54 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6291
Location: Canada
psycopathicteen wrote:
I came up with a math equation to eject objects straight vertically and horizontally so that the physics work the same both ways.

Well if your rotation matrix coefficients are A B C D:
Code:
A B    cos a  sin a    A B
    =               =
C D   -sin a  cos a   -B A

If you wanted to invert that to make vectors that are straight vertical/horizontal after the rotation, you can just invert the angle, which just means you swap B with -B in the result. (because: cos a = cos -a, sin a = -sin -a)

So going back and forth between the pre-rotation space and the post-rotation space is just the same transform with that one sign flipped.

Your inversion with the division isn't wrong, I don't think, but there's an easier way.


Top
 Profile  
 
PostPosted: Sun Apr 29, 2018 7:04 am 
Online
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3316
Location: Nacogdoches, Texas
Making the hitbox of everything a circle has been brought up, but would it be at all feasible to check a rotated box against the collision map?


Top
 Profile  
 
PostPosted: Sun Apr 29, 2018 7:08 am 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2648
rainwarrior wrote:
psycopathicteen wrote:
I came up with a math equation to eject objects straight vertically and horizontally so that the physics work the same both ways.

Well if your rotation matrix coefficients are A B C D:
Code:
A B    cos a  sin a    A B
    =               =
C D   -sin a  cos a   -B A

If you wanted to invert that to make vectors that are straight vertical/horizontal after the rotation, you can just invert the angle, which just means you swap B with -B in the result. (because: cos a = cos -a, sin a = -sin -a)

So going back and forth between the pre-rotation space and the post-rotation space is just the same transform with that one sign flipped.

Your inversion with the division isn't wrong, I don't think, but there's an easier way.


I thought about that, but I realized the character's running speed would be wrong. I'll show a drawing of what I mean by it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google Adsense [Bot] and 4 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group