Physics: Tween no effect on Collider? Am I right concluding that Nodes animated via Tween have no effect on Colliders? Specifically I have a node A with a boxcollider2d and rigidbody (type:static) and boxcollider2d set as sensor. I have another node B with rigidbody (type:kinematic) and boxcollider.
Physics used in settings: Box2D
Scenario 1:
Node A with Rigidbody (type: Static); BoxCollider2D set as sensor
Node B with Rigidbody (type: Dynamic)
=> Node B falls into the sensor area of Node A. Node A’s callbacks DO trigger.
Scenario 2:
Node A with Rigidbody (type: Static); BoxCollider2D set as sensor
Node B with Rigidbody (type: Kinematic)
=> Node B is animated via Tween into the position of Node A’s sensor area. Node A’s callback DO NOT trigger. Why?
When I animate B to the position of A , nothing happens, ie the callbacks which triggered without problem in scenario 1 do not trigger.
Thank you for the reply. My fault not to mention it (will edit the question). The type of Rigidbody is kinematic.
The problem arises only when animating Node B into the collider(sensor) area of Node A via Tweens. In this case, the callbacks of the sensor of Node A do not trigger. But they trigger when I use regular physics with type dynamic and let B drop in the area of node A.
This code works fine when the otherCollider’s Rigidbody is of type:Dynamic. It stops working when the type is set to Kinematic.
I have changed the overall logic of my code and I’m using tweens instead of physics. But for future reference it is valuable to know why the problem occurs.
Every tile (dark brown) in the background is a sensor, sensing the diamond type whenever a diamond “touches” the tile’s collider.
Instead of animating each diamond via tween I wanted physics do the job. So each diamond is sitting above another stone until the diamond below stops existing, in which case every diamond above is falling down to a hidden ground below the bottom tiles.
In this setup each diamond had a RB with type Dynamic and the tile behind had a RB of type static. When I change the type of the diamond to Kinematic, and animate the stone via tween, the tiles stop sensing the stone. This happens with Box2D.
I know the whole setup is nonsense in the first place, I was playing around to test some ideas (I changed everything in the new version, using tweens and builtin physics.). But nevertheless the problem occurred exactly then. Change from Dynamic to Kinematic, and sensors stop triggering although stones are exactly on top of them.
The code below should not distract. There is nothing to see here. When a diamond is clicked, it gets destroyed. Each Tile has access to the diamond occupying the position, so it can call moveDown() from the diamond script. Nothing special. Very simple (although confusing for someone not knowing the relationship between nodes). When testing (with type kinematic) the stones fall to the position of the proper tiles, but the sensors do not trigger.
**Again, thank you for your time and your effort @zhangxm *. As I said, I changed everything, the whole logic, and code, and everything described here do not apply anymore. It is only interesting to see from where the problem arises. Should I delete this entry?
From Tile.ts:
onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact : IPhysics2DContact | null) {
let stone = otherCollider.node;
let id = stone.getComponent("Stone").getID();
this.setState(id);
....
}
I was not allowed to upload a video, so I shared the screenshot above. The rest is console output, which logs out the color of the stone “console.log(this.getID()”, triggered inside the “onBeginContact” callback above.
Again, thank you for your effort. I appreciate it.