Rotating collision with a rotating map

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Path
Prole
Posts: 10
Joined: Tue Nov 17, 2015 8:06 pm

Rotating collision with a rotating map

Post by Path »

Hi, i'm using a tile map that rotates around its center, and i need consistent collision on each tile that will stay in the exact location and rotation as each tile. the issue is that all the tiles are rendered through love.graphics.draw, and when i rotate them with love.graphics.rotate and love.graphics.translated, the exact location of the tiles cannot be found, since their x or y value doesn't actually change. Is there some way to either get the position of the tiles after they are rotated and translated, or is there a way to also rotate all collision boxes in the same manner
pedrosgali
Party member
Posts: 107
Joined: Wed Oct 15, 2014 5:00 pm
Location: Yorkshire, England

Re: Rotating collision with a rotating map

Post by pedrosgali »

Hi, do you need to rotate your collisions? If the map is rotating on the screen their map position wont change, just the place you are drawing them. As far as your collisions are concerned the map wouldnt have moved at all. I may have misunderstood your question though.

Code: Select all

if not wearTheseGlasses() then
  chewing_on_trashcan = true
end
Path
Prole
Posts: 10
Joined: Tue Nov 17, 2015 8:06 pm

Re: Rotating collision with a rotating map

Post by Path »

hi, this is what my map is doing
Screen Shot 2017-06-11 at 3.00.22 AM.png
Screen Shot 2017-06-11 at 3.00.22 AM.png (19.45 KiB) Viewed 6076 times

this is one position where the map's rotation is 0. however, the game i'm making will have the map rotate in order to manipulate physics objects on the map, sort of like a pachinko puzzle, or one of these things

Image



here is a case where the map is rotated
Screen Shot 2017-06-11 at 3.00.34 AM.png
Screen Shot 2017-06-11 at 3.00.34 AM.png (24.12 KiB) Viewed 6076 times
each tile is an 8x8 square, and i need a system where the collision boxes will maintain the same position and rotation as each tile. However, the tile's x and y coordinates remain unchanged, since rotation/translation doesn't leave behind any gettable x or y coordinates.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Rotating collision with a rotating map

Post by MadByte »

The map rotation/tilting doesn't need to affect the collisions and tile positions at all. You could just visually rotate and tilt the map and apply forces to the objects (ie. the ball) based on the rotation and tilting values you got.
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Rotating collision with a rotating map

Post by yetneverdone »

You can use love.graphics.rotation() to rotate all of your visuals. And with love.graphics.translate(), you can easily get the points
Path
Prole
Posts: 10
Joined: Tue Nov 17, 2015 8:06 pm

Re: Rotating collision with a rotating map

Post by Path »

yetneverdone wrote: Sun Jun 11, 2017 11:07 am You can use love.graphics.rotation() to rotate all of your visuals. And with love.graphics.translate(), you can easily get the points
the problem is that collision boxes aren't rotated by love.graphics.rotation, only the tiles are. the collision boxes are just coordinates that are being defined. and i already use love.graphics.rotation and that just rotates all the images, but it doesn't help since the collision doesn't move or rotate at all
MadByte wrote: Sun Jun 11, 2017 10:27 am The map rotation/tilting doesn't need to affect the collisions and tile positions at all. You could just visually rotate and tilt the map and apply forces to the objects (ie. the ball) based on the rotation and tilting values you got.
So essentially use a camera and rotate it, but apply the forces to the movable objects instead? that sounds feasible so i might try it
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Rotating collision with a rotating map

Post by yetneverdone »

May i know what you use for your collision boxes?
Path
Prole
Posts: 10
Joined: Tue Nov 17, 2015 8:06 pm

Re: Rotating collision with a rotating map

Post by Path »

yetneverdone wrote: Sun Jun 11, 2017 11:20 am May i know what you use for your collision boxes?
im using boundingbox.lua which was on the love site
https://love2d.org/wiki/BoundingBox.lua

im trying to avoid using actual physics and rather revert to simple gravity and velocity for the project, but i do want some form of collision, working at least along 90 degree angles
Path
Prole
Posts: 10
Joined: Tue Nov 17, 2015 8:06 pm

Re: Rotating collision with a rotating map

Post by Path »

Alright so i found a solution to what i'm saying. To get collision points to rotate and transform alongside the visual tilemap, i rotated all the points around the same origin the map was on, which produced good results

Image

dx = xvertex - xaxis
dy = yvertex - yaxis

x = cos(θ) * dx - sin(θ) * dy + xaxis
y = sin(θ) * dx - cos(θ) * dy + yaxis

thank you to everyone that helped out
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 212 guests