Showing posts with label touch. Show all posts
Showing posts with label touch. Show all posts

Saturday, September 18, 2010

Keeping Their Distance

I've refined the code that determines the placement of the kids. Now the code ensures that the kids aren't placed to close. Every kid placed after the first one is checked for whether or not they are in the vicinity of any of the kids that have already been placed.

Here's a bit of code:
public bool DistanceCheck()
{
disCheck = false;

for(int i=0; i<antal-1;i++)
{
if ( ((kids[i].transform.position.x-temp.transform.position.x)*(kids[i].transform.position.x-temp.transform.position.x)) + ((kids[i].transform.position.y-temp.transform.position.y)*(kids[i].transform.position.y-temp.transform.position.y)) < 200)
{
disCheck = true;
}
}
return disCheck;
}

And a video with the latest improvement:

To sum up, reds are crying, blues are about to and green kids are okay for now. When the crying kids are tapped they turn happy (no paedophile thoughts intended).

Friday, September 17, 2010

Touchy Success


Finally the touch input is working. I thought I would be able to "talk" directly to a method on a game object from another class e.g. objectname.method. I have now realised that I needed to use the method getComponent() to access the methods of the objects. This has taken forever to realise. But now the code works! It needs refining but it works.


When I touch the screen a ray is sent along the z-axis into the 3d space (world space I guess). Whatever the ray collides with is "registered" in the raycast method's collider. Assuming the object the the ray collides with is an Kid object I can then access the methods in the kid and change it's state.