Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

[FIXED] Collision Filters Not Working
Started by JoshuaNovak919 Oct 29 2013 10:56 AM

12 replies to this topic
collision filter physics graphics 2.0 corona bug
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

JoshuaNovak919

[GLOBAL: userInfoPane.html]
JoshuaNovak919
  • Enthusiast

  • 55 posts
  • Enterprise

Collision filters don't seem to be working with Graphics 2.0, this is a big issue when making a game. Any idea when this may be working again?



[TOPIC: post.html]
#2

ingemar

[GLOBAL: userInfoPane.html]
ingemar
  • Corona Geek

  • 2,733 posts
  • Enterprise

Collision filters are working with my test apps.

 

One thing though: At the moment, Physics doesn't take an object's anchor point into consideration.

In physics "hybrid" mode it looks like all objects are in the correct location after setting the anchor point, but they're still in the default (0.5,0.5) location with regards to collision events.



[TOPIC: post.html]
#3

JoshuaNovak919

[GLOBAL: userInfoPane.html]
JoshuaNovak919
  • Enthusiast

  • 55 posts
  • Enterprise

That is still a pretty big issue to not be working and may be the reason my game and my collision samples aren't working. Any idea when Physics will take an object's anchor point into consideration again?



[TOPIC: post.html]
#4

walter

[GLOBAL: userInfoPane.html]
walter
  • Moderator

  • 726 posts
  • Alumni

@JoshuaNovak919, first off, reference points are not the same as anchor points.

 

Now in the 1.0 engine, Box2D ignored the reference point because Box2D does a real physical simulation, and therefore uses the center of mass.

 

In the 2.0 engine, Box2D imposes the same sort of limitations, so the point of rotation will be in the object's center of mass. So the anchor point similarly gets ignored.



[TOPIC: post.html]
#5

JoshuaNovak919

[GLOBAL: userInfoPane.html]
JoshuaNovak919
  • Enthusiast

  • 55 posts
  • Enterprise

Hmm i'm not 100% sure what you mean. I do know it isn't working at all for me. My game i had working with the previous graphics engine doesn't work now, the enemies fall through the ground and the balloons demo let the balloons go through the walls etc. I'll rebuild the balloon demo again and post it.



[TOPIC: post.html]
#6

JoshuaNovak919

[GLOBAL: userInfoPane.html]
JoshuaNovak919
  • Enthusiast

  • 55 posts
  • Enterprise

Ok i have the collision filter sample ready. I basically just added anchor points to the walls and color so you can see them. Is there a place i can send it/post it? If you run it with the newest daily build of Graphics 2.0 the balloons bounce and then just fall off the screen. I have the same issue in my game with enemies falling through objects they shouldn't etc.



[TOPIC: post.html]
#7

ingemar

[GLOBAL: userInfoPane.html]
ingemar
  • Corona Geek

  • 2,733 posts
  • Enterprise

I filed a bug report (Case 27433) earlier today showing the issue.



[TOPIC: post.html]
#8

ingemar

[GLOBAL: userInfoPane.html]
ingemar
  • Corona Geek

  • 2,733 posts
  • Enterprise

@walter

 

This is a regression issue as Physics does respect reference points in G1.0 (at least when talking about the positioning of static objects). I've used it many times in apps developed with G1.0. 

 

In G2.0 hybrid mode, the objects seem to be in the correct location when setting anchor points, but the actual object with regards to collisions isn't.

 

I've filed a bug report as indicated above.

 

Below you'll find some code (bouncing ball) that has been modified to run with *both* G1.0 and G2.0 to show the issue. 

(In G2.0 the ball bounces off a wall that's not there).

 

--
-- main.lua
--

local physics = require("physics");

physics.start();
physics.setGravity(0, 0);
physics.setDrawMode("hybrid");

local coronaBuild = system.getInfo("build");
local coronaVersion = tonumber(coronaBuild:sub(coronaBuild:find("%.")+1));

-- event handler
local onEvent = function(event)
	print("onEvent",event.phase)
end


-- display some lines
local fromX = display.contentCenterX;
local fromY = 0;
local toX = 0;
local toY = display.contentHeight;

local lineTable = {};

for i = 1, 240 do
	lineTable[i] = display.newLine(fromX, fromY, toX+(i*2), toY);
	lineTable[i].strokeWidth = 1;
end

-- create walls
local wall1 = display.newRect(0, 0, 20, display.contentHeight);

if (coronaVersion >2000) then
	wall1.anchorX, wall1.anchorY = 1, 0;
else
	wall1:setReferencePoint(display.TopRightReferencePoint);
end

wall1.x, wall1.y = display.contentWidth-10, display.contentCenterY;
physics.addBody(wall1, "static", {friction=0.0, bounce=1.0});
wall1.alpha = 0.2;
wall1.isSensor = false;
wall1:addEventListener("collision", onEvent);


local wall2 = display.newRect(0, 0, 20, display.contentHeight);

if (coronaVersion > 2000) then
	wall2.anchorX, wall2.anchorY = 0, 1;
else
	wall2:setReferencePoint(display.BottomLeftReferencePoint);
end

wall2.x, wall2.y = 10, display.contentCenterY;
physics.addBody(wall2, "static", {friction=0.0, bounce=1.0});
wall2.alpha = 0.2;
wall2.isSensor = false;
wall2:addEventListener("collision", onEvent);



-- create moving objects
local ball = display.newCircle(display.contentCenterX, display.contentCenterY+50, 20);
ball:setFillColor(0.6);
physics.addBody(ball, "dynamic", {radius=20});

local ball2 = display.newCircle(display.contentCenterX, display.contentCenterY-50, 20);
ball2:setFillColor(0.6);
physics.addBody(ball2, "dynamic", {radius=20});

-- set in motion
ball:setLinearVelocity(250, 0);
ball2:setLinearVelocity(-250, 0);
 

 

 

 



[TOPIC: post.html]
#9

ingemar

[GLOBAL: userInfoPane.html]
ingemar
  • Corona Geek

  • 2,733 posts
  • Enterprise

This issue has been fixed in build 2034.



[TOPIC: post.html]
#10

JoshuaNovak919

[GLOBAL: userInfoPane.html]
JoshuaNovak919
  • Enthusiast

  • 55 posts
  • Enterprise

Awesome!! Works perfect now. Thanks!



[TOPIC: post.html]
#11

walter

[GLOBAL: userInfoPane.html]
walter
  • Moderator

  • 726 posts
  • Alumni

Yup, just the one caveat you should be aware of. From the checkin comment in build 2034: 

 

"you cannot change the anchor point after the addBody call."



[TOPIC: post.html]
#12

JoshuaNovak919

[GLOBAL: userInfoPane.html]
JoshuaNovak919
  • Enthusiast

  • 55 posts
  • Enterprise

Yeah i noticed that. That is something i can work around for now.



[TOPIC: post.html]
#13

spacewolf

[GLOBAL: userInfoPane.html]
spacewolf
  • Contributor

  • 298 posts
  • Enterprise

Is there something special you have to do to get a group image for physics to respect the anchor point? I set my group anchorY to 0 (2 images inside the group are positioned via anchorY = 0). I addBody the group but hybrid physics mode shows it centering the collision box as anchorY = .5

 

What gives?




[topic_controls]
[/topic_controls]