Making two object collide but moving like kinematic objects - lua

I'm working on a "Words in a pic" clone and I have different images representing each letters and empty boxes where the letters should be put in to.
When I drag the letters I want them to be dragged like when it is a static body i.e. just up, down, left and right (no turning or spinning) and when the item is within the box it should stay within that box, otherwise it should go back to it's original position.
The thing is that static objects can't collide with another static object nor can a kinematic object collide with another object so I need to use Dynamic if I have understood it correctly?
However how do I do so when the drag event is activated the body, the letter image, moves like a static or kinematic body (only up, down, left and right) but also detects collision between a letter image and a empty box image?
Thanks for helping me with this, I have not been able to find any information on how to solve this problem!

This was easier than I though, you set the items as "dynamic" and then object.isSensor = true, to make it not rotate object.isFixedRotation = true and also deactivate the gravity through object.gravityScale = 0

Related

Move object left and right in ARKit session

How to move an object left and right in ARKit scene without changing its Y-axis, if its in the air then it doesn't change that and just move left and right in screen?
This will be a very general example, I could get more specific if you make your question more detailed or give an example of what you are trying to do.
Lets say you want the object to just move on it's x-axis and you had an object of type SCNNode called selectedObject, you could do something like this
selectedObject.position = SCNVector3Make(value, selectedObject.position.y, selectedObject.position.z)
In this case, you can provide the value you want for the x axis position while maintaining the position the object has on the y and z axes.

Modify interaction - How to get the segment which has been hovered

I am using openlayers-3 modify interaction to edit vector layers. When a polygon/polyline is being edited, if mouse is close to a line segment, a small circle is drawn and dragging it creates a new vertex or moves an existing vertex, depending on where on the segment I was hovering.
Now, sometimes this is very difficult to understand if I am hovering on an existing vertex, or on middle of a segment. I have thought about two solutions to the problem:
Highlight the segment I am hovering with a different style so that I
can see its edges.
When hovering on an vertex, style the small
circle with a different style.
Is there a way to achieve any of the two?
It can be done changing the interaction condition like:
var selectPointerMove_Highlight = new ol.interaction.Select({
condition: ol.events.condition.pointerMove
});
map.addInteraction(selectPointerMove_Highlight);
I have an online example.

Find available grid position

I'm building a color box connecting game with objective-C and trying to figure out how to find the correct position when a block of boxes is placed incorrectly over another block of boxes.
See the attach image. In the image, you only need to move the left box one step to the right in order to connect the boxes and win.
However, if you place the left box on top of the other box (Image 2), I want to move it to the closest available free grid position.
This would be easy if the box was a simple square (a 1x1 grid, 2x2 grid, etc), but since the boxes can be complex, It's harder. There might also be a lot of boxes on the grid.
Any suggestions would be very appreciated.
If you're new to heuristics like this, just take the KISS approach.
It couldn't be easier...
The user tries the object at x,y ok?
It does not "fit" there.
So, simply "spiral" outwards, trying it in other possible places.
Just keep trying until you find one where it fits.
234
915
876
so that's like "radius 1", you see? then try "radius 2"
and so on.
It's that easy. Just keep trying until you find one that "does work".
Work from the start position outwards, so that, you find the closest one.

Adobe flash(cs5) how to replace animations

I have a symbol of a person standing, he have child movieClips like hands, legs, head, body....so then if i press a button or click in the stage how do i need to change the animation instantly?
I suppose:
1) create a new movieClip that has all the same parts but animated as walking(for example) and then make something like:
if(keypressed)
{
person.replaceSymbol(myNewAnimatedSymbol); //method that not exist
}
2) for example if my standing animation longs from 1 to 30, i can make another animation in the same line let's say from 31 to 60 where he is running and then write:
if(keypressed)
{
person.legs.gotoAndPlay(31); //in the 60 frame he go back to 31 by using gotoAndPlay(31)
person.hands.gotoAndPlay(31);
person.body.gotoAndPlay(31); //and so on...
}
Can you give me an advice of which of methods I need to use? or if you have a better idea how to make it...
Hm-m-m. I'd say your second approach is easier to both draw and control, especially if it'll eventually come to reskinning your MC, say your person will get dressed in a cloak that's attached to the body and arms, your "new animated symbol" will likely require a change to accommodate that clothing, while in case of one symbol you can assign its parts another look, like say person.hands.cover=clothing.handpart; person.legs.cover=clothing.legpart etc, and then the animation will contain references to cover being changed, so that correct parts of clothing will appear around all the moving parts.
In fact, you might not need separating your person into different body, hands, legs etc MCs, but instead make it so that your person's legs are a container that can hold either a bare body part (naked leg drawing) or a dressed body part (a boot, pants, etc), and animate the main part by making these containers move according to how a person should walk, stand, run, attack etc etc., so that you will have a single point to dress the entire set of your person's animations.
It depends for example my character has around 100 animations. Putting them in a single timeline and telling them to go from this label to that label (or frame) is a huge mess to manage.
So I have 100 library items with export symbols. I keep on switching between them. This makes it easy to manage.
So, I think the question is how many animations do you have? Can you manage them in a single timelines? If you can , I'd say go with labels or frame jumps.
Both of your methods are correct and your second method would be faster because you're not adding or removing anything from the display list.

corona drag and drop an object on container or reference

I am developing a game and one level is solving a jumbled up word. The letters are images like tiles and I am trying to either click a letter and this will move to the first of the allocated spots to solve the word or to actually drag the tile to the spot. Can anyone help me implement this?
To drag an object see this tutorial:
http://www.coronalabs.com/blog/2011/09/24/tutorial-how-to-drag-objects/
If you just want to tap them and have them move to where you want them, then something like this might work for you:
local function moveTile(event)
-- put your code here to move the tile
-- figure out the X, Y where the tile needs to move to
-- either just set the X, Y on the tile or use a transition.to() call
-- to animate it.
local thisTile = event.target
thisTile.x = destinationX -- you have to figure out what destinationX is.
thisTile.y = destinationY -- figure this out too
return true
end
Then on each tile after you create it, simply add this line to make it tappable:
tile:addEventListener("tap", moveTile)

Resources