2D Physics Puzzle Kit

Hi Dreeka -

RE: Memory Leak
I believe I have found the memory leak.

In FeedbackManager.cs, the Disable() method needs to have this line added:

this.target = null;

Without it, the update method will constantly attempt to manipulate the transform. It’s interesting that it eats memory, but nonetheless, nulling that object stops the memory consumption. This is also what eventually drops the FPS. Please review and see if that is indeed the required fix. I’ll gratefully accept payment in terms of a copy of your 2d infinite runner kit :wink:

Feedback Circle
Regarding the issue people are experiencing on mobile where the feedback circle goes red, I seem to have fixed it but in an ugly way. This is probably not the best fix but I’ll bring it to your attention if it helps you resolve the issue. What appears to happen on some mobile platforms is that the object is colliding with its own feedback object, causing it to go red. My hack around this was to check for this in the objectbase OnTriggerStay method:

// avoid treating hit with own feedback circle as a invalid pos
if (!other.name.Contains (“Feedback”)) {
validPos = true;

Seems to be a short term hack/fix.

cdutoit thanks for the time to write down this answer. Thank you very much. I tried the solution about the memory leak and it does help indeed. Performance on my Galaxy Tab 10.1 is up. It doesn’t drop below 15fps now and with some optimisation of the draw calls I think it will be even better.

Unfortunately the second solution does not work for me. Can you please tell me if have undestood well.

In file TriggerRegister.cs

have this method ?

//Called when the object hit something in trigger mode
void OnTriggerStay2D(Collider2D other)
{
objectBase.SetValidPos(false);

// avoid treating hit with own feedback circle as a invalid pos
if (!other.name.Contains (“Feedback”)) {
objectBase.SetValidPos(true);
}

}

Thanks in advance!

@nickthegreek - glad the memory leak fix worked for you.

My feedback circle fix is not great and we’ll wait for Dreeka to respond but the possible fix is this:

You modified the wrong file.
In the ObjectBase.cs script, modify this method:

void OnTriggerStay2D(Collider2D other)
{
if (!other.name.Contains(“Feedback”)) {
validPos = true;
}
}

Undo your change on the TriggerRegister method you made.

Unfortunately it doesn’t work in my case. Now the item stays green everywhere. It does not turn red at all so item can be placed anywhere…

Same here. Looking at the code it will let you place an object anywhere as long as any colliding object does not contain ‘Feedback’ in its name. For example on top of another object.

So the test should be reversed to makes sure the name does contain ‘feedback’.

Should it not be:
void OnTriggerStay2D(Collider2D other)
{
validPos = false;
if (other.name.Contains(“Feedback”)) {
validPos = true;
}
{

That way all collisions will prevent placement of the object except for collisions with the feedback collider.

This code seems to work, though I only get the original error occasionally so can’t be sure it’s working properly.

I made another tweak if anyone wants to use it. This modifies the LevelManager script to delay for 1 second before the level starts after the player presses the play button (you can adjust the delay time of course). This feels a bit more polished to me, as it gives the player a bit of time to ‘brace’ for the level to begin.

Replace the EnableScene method and add a “WaitThenEnable” routine:

public void EnableScene()
{
StartCoroutine (“WaitThenEnable”);

}

IEnumerator WaitThenEnable()
{

// wait the delay time…
yield return new WaitForSeconds(1);

// code from the original Enable method
inPlayMode = true;

foreach (ObjectBase item in activeObjects)
item.Enable();

}

This is in line with Amazing Alex, which is one of the best of this genre.

Yes this works now fine! Thanks for this pumpkinszwan! I am really greatful to both of you.

I have noticed a bug in resolution manager as well. It does not work well in my test devices. The script thinks that all screen have an aspect ratio of the ones the are predefined. It tries to calculate the aspect ratio of the device but in Android things are not that easy. In my test devices here are the results :

Device Aspect Ratio of the device

Nexus 10 80x47
SIII mini 5x3 (the only one that works fine out of the box)
Galaxy Nexus 299x180
Pipo S1S 128x69
Galaxy Tab 10 80x47

You can add those aspect ratios as well in ResolutionManager as a temporary solution. But still there will be devices that this won’t work. I am planning to re-write that script later on.

@pumpkinszwan: doh - thanks - I had typed that from memory and you’re absolutely right. Thanks for catching the inverted logic.

Hi all, thanks for the help offer in this forum, someone knows that line modified to go two GoalMaker on screen, I modified lines but I’m fairly new and not come out, thanks to everyone and especially to pumpkinszwan for the double goal, Thx

Do you mean to add two markers on the screen to indicate the goals? You may have to just add them manually. I haven’t bothered with that yet.

I am planning on making a script to automate the markers so the game will automatically centre them on any objects marked as goals/markers, but I haven’t looked into how it currently works.

I’ve managed to get some automatic goal/target markers working, though it could do with a bit more polish. Read the issues at the bottom of this post before deciding to implement this. Also: you MUST have my ‘multiple goals’ script, posted above, to use this code.

You need to add some code to the GUIManager script and create a couple of new prefabs.

NOTE: I’m not posting the complete script because it contains a lot of custom stuff that is specific to my modifications to the engine, and the script would break your game, so follow the steps below carefully, and post here if you get stuck

1) Add the following variables to the top of the GUIManager script
// these will hold our marker prefab items, which will be instantiated as needed
public GameObject targetMarkerPrefab;
public GameObject goalMarkerPrefab;

// this will hold the goalslist, which will be extracted from the Overlord object, in the GoalManager script
// this assumes you have implemented my GoalManager script, where the targets/goals are stored in an array of GoalAndTarget class
GoalManager.GoalAndTarget[ ] GoalsList;

// arrays to store the markers, which will be instantiated when required
// the original ‘markers’ array will not be used for the target/goals, but will still be used to show the ‘tick’ when a level is won
List targetMarkers;
List goalMarkers;

2) In the GUIManager script’s Start() method, add the following lines BEFORE the ‘StartCoroutine(ShowMarkers(2)));’ command

// get the level target(s) and goal(s)
// this is coded to work with arrays (to allow for multiple targets and goals), and this will only work correctly in conjunction with a modified GoalManager script
GoalsList = GameObject.Find (“Overlord”).GetComponent().GoalsList;

// initialize our lists
targetMarkers = new List();
goalMarkers = new List();

// create all the markers required and set their scale to 0,0,0 (so they are not visible until needed)

foreach (GoalManager.GoalAndTarget targetAndGoal in GoalsList)
{
// create a new target marker for each target at the target’s position and set the marker’s scale to 0
GameObject newTarget = Instantiate(targetMarkerPrefab, targetAndGoal.target.rigidbody2D.transform.position, targetAndGoal.target.rigidbody2D.transform.rotation) as GameObject;
newTarget.rigidbody2D.transform.localScale = new Vector3(0,0,1);
targetMarkers.Add(newTarget);

// do the same for the goal marker(s)
// note: this will create duplicates if the same goal object is used for multiple targets, but they will simply overlap and appear as one, so it shouldn’t be a problem
// there may be room for optimisation here
// check for null goals, which are required for the balloon popping target
if (targetAndGoal.goal)
{
GameObject newGoal = Instantiate(goalMarkerPrefab, targetAndGoal.goal.rigidbody2D.transform.position, targetAndGoal.goal.rigidbody2D.transform.rotation) as GameObject;
newGoal.rigidbody2D.transform.localScale=new Vector3(0,0,1);
goalMarkers.Add(newGoal);
}

3) Replace the HideMarkers method with the following code (I recommend commenting out the original to keep it handy)
void HideMarkers()
{
markersVisible = false;
StopCoroutine(“ShowMarkers”);

// replacement code for the new method of showing markers
foreach (GameObject targetMarker in targetMarkers)
targetMarker.rigidbody2D.transform.localScale = new Vector3(0,0,1);

foreach (GameObject goalMarker in goalMarkers)
goalMarker.rigidbody2D.transform.localScale = new Vector3(0,0,1);
}

4) Replace the ShowMarkers method with the following (comment out the original again)

IEnumerator ShowMarkers(float showTime)
{
markersVisible = true;
yield return new WaitForSeconds(1);

//Scale up the markers

foreach (GameObject targetMarker in targetMarkers)
StartCoroutine(ScaleObject(targetMarker.transform, Vector2.one, 0.25f, 0));

foreach (GameObject goalMarker in goalMarkers)
StartCoroutine(ScaleObject(goalMarker.transform, Vector2.one, 0.25f, 0));

yield return new WaitForSeconds(showTime);

//Scale down the markers to zero
foreach (GameObject targetMarker in targetMarkers)
targetMarker.transform.localScale= Vector2.zero;

foreach (GameObject goalMarker in goalMarkers)
goalMarker.transform.localScale= Vector2.zero;

markersVisible = false;
}

  1. Create 2 new prefabs from the markers in GUIManager > Markers by dragging goalMarker and targetMarker into your Prefabs folder.
  2. Add a Rigidbody2D to the 2 new prefabs, and make them kinematic, 0 mass, and 0 gravity scale (so they don’t interact with the scene)
  3. Select the GUIManager and you will have two empty variables in the editor called ‘Target Marker Prefab’ and ‘Goal Marker Prefab’. Drag your new prefabs into the appropriate slots.

Now your levels will automatically display markers for all goals/targets, and you don’t even have to place them yourself!

ISSUES
This is a quick and dirty implementation. The default marker for the goal is an arrow, and this will display in the centre of the goal item, so you should change this (shouldn’t be too hard). I am thinking of maybe implementing a few different types of marker to use depending on the items and their location (e.g. an arrow pointing to the right placed to the left of the goal so it points AT the goal).

With multiple goals or targets there is no indication which goal goes with which target (only a problem if you use different goals for the targets). I will try to implement a way to get around this, such as different coloured markers for each goal/target pair.

EDIT: New issue: If you use the ‘empty target’ prefab in your game you will need to add a rigidbody2D to it due to the way my code accesses the item’s position (so it knows where to place the marker). Add it in the same way you add it to the other prefabs (kinematic, not mass, no gravity).

EDIT2: Added check for a null goal in case the target is popping a balloon (which has no associated goal). Null goals are simply ignored

I’ve got another bit of code, which I think improves the display of markers.

I’ve modified the ReceiveInput method of the GUIManager script to do (re) show the goal/target markers when a level is paused and when a level is restarted from the pause menu. I think this helps the player, as it lets them pause the game to get reminded where the goals/targets are, and again if the restart the level they will again see the markers.

The code below replaces the ReceiveInput method completely. All it really does is call the ShowMarkers coroutine when specific conditions are met. It’s pretty easy to chop and change:

public void ReceiveInput(Transform button)
{
if (levelState == LevelState.inChange)
return;

switch (button.name)
{
case “Play”:
if (levelState == LevelState.inPlanning)
PlayLevel();
else if (levelState == LevelState.inPlaying)
{
StopLevel();
StartCoroutine(ShowMarkers(2));
}
break;

case “Pause”:
if (levelState == LevelState.inPlanning)
PauseLevel();
else if (levelState == LevelState.inPause)
UnpauseLevel();
break;

case “ToolboxButton”:
ToolboxManager.Instance.ButtonPressed();
break;

case “Restart”:

LevelManager.Instance.RestartScene();
StartCoroutine(ShowMarkers(2));
break;

case “FinishRestart”:

RestartFromFinish();
break;

case “LevelSelect”:
Application.LoadLevel(levelPackName());
break;

case “NextLevel”:
if (levelNumber() < 12)
Application.LoadLevel(nextLevel());
break;
}

StartCoroutine(Animate(button, 0.1f, 0.15f));
}

Has this update for iOS and Android came out yet?

iOs dont know but Android is working. Still waiting for the update with second level page example and so .

Hey,

Sorry for the late reply! I am having an test heavy week, and I have much to learn. Still, I know it is not fair of me to keep you waiting for soo much time. So, from now on, I am going to visit the forums every day, and I am going to answer your questions within 24 hours.

cdutoit, nickthegreek, pumpkinszwan:
Thanks for highlighting problems, and helping the community! I really appreciate it! :slight_smile:

ionbrainz:
The mobile support update is out, but there is a bug in the touch controls (see above). It will be fixed in the next update.

UltraTM:
I will provide it as soon as possible.

No problem Dreeka- stress in reallife and work ist still priority :slight_smile:

Happy to announce my game based on this kit is now published on both platforms.

For those of you familiar with the kit, these are some of the major changes I made:

First, all the components are basically pipes since that is the object of the game
I made multiple goals
I added a hint capability which shows text at the start of certain levels
I added new pipe components, such as the accelerator which speeds up the ball which you need to go “up”, and the multiplexer which duplicates the ball which you need when you have multiple goals.
New components were created using playmaker, so I had to modify the code at certain points to raise playmaker events to cue off of
I changed the level manager to start at level 1 unlocked and all the rest locked, and then they progressively unlock
I added a “snap” function as you rotate to line it up on the horizontal and vertical
I added music
I added the stop/exit
I added the sound toggle on/off
Added Chartboost
And then created the levels of progressing difficulty using all the pipe components I supply.

At least that’s it in a nutshell. Overall very happy with the outcome. Getting good reviews so far. One “1 star” review since the reviewer says it crashes on ios 7.1 iphone 5 and I don’t have any way of testing that configuration. I suspect (hope) it is to do with a lack of memory on his device but its a shame to get 1 star after all that work. If any of you have a iphone 5 with ios 7.1 and are willing to try it for me, I’d really appreciate it. It is a free download. If there is a crash problem on that device I need to find it ASAP.

The link to ios or android version are here on the facebook page

Thanks to the community and the author of the original toolkit. Now just to go figure out how to get more downloads and positive reviews… :wink:

@cdutoit

The game looks great. I’m charging up (and dusting off!) my old Android tablet to give it a try. Do you have any plans to share the ‘snap’ functionality code? The pipes in the stock engine could really do with Amazing Alex style snapping. Without it pipes can be a bit fiddly.

My own game isn’t finished yet, but here’s a quick video of it (currently untitled):

I’ve implemented a bunch of stuff, off the top of my head:

  • multiple goals
  • new objects/prefabs: (cannon, ‘spray’ object (water hose that pushes items that fall within its path), trapdoor triggered by a button, popcorn box that spills popcorn kernels when it’s knocked over
  • sound toggle/music/SFX
  • tweaks to some of the built-in objects (e.g. making the balloon faster)

I still have a bunch of bugs/glitches to fix (you can see a few clearly in the video, such as the toolbox ‘hiding’ my goal markers), and I want to do a bunch more levels (currently have about 40, of which 12 are really simple tutorial levels).

The game (currently untitled) will be available on Windows 8 and Windows Phone 8 soonish, with hopefully Android and iOS versions to follow.

cdutoit, pumpkinszwan:
Really good job with the kit! It is really good to see when people use our kits to create their games.
I wish you the best of luck with your games! :slight_smile:

I congratulate you both for your work …
I’m new to Unity and as a novice programmer still … some tips to learn how to program in C # or Js, books, tutorials, etc …

Thank you very much and good luck with your work.