how can my move a obect alon with the player
check the bellow pic. the green one is my player and the red one is obstacle when i tap the player has to come along with the obstacle . am doing Lerp for the movement of player whenver it collides am making the obstacle as a child to the player. it done the job job but not properly.
i mean some overlapping is there like in the 2nd fig. because of the speed it is going like that.
how can i do it.
If possible, edit your question to be more readable please. :) I understand you want to place something like a marker (obstacle) that the player will be moving towards. When the player reaches the marker, it should "disappear"?
thanks @RyFridge
it won't disappear.the player movement is grid wise. it has to move 1step up,down,left,right... according to user input(i mean in which way he swipe). if there is cube(obstacle) on the way it has to take that cube along(or it has to push that obstacle).for swipe am done it exactly what i need.
But there is a another control that is tap. if the user tap on horizontal or vertical grids to the player it has to move on which grid he tap. that is also did.
now suppose on the way(the movement is going when user tap) of the player obstacle is there.the player has to push that cube to the position where he tap.
see the bellow pic i think u can understood better.
Answer by RyFridge · Jan 04, 2016 at 03:40 PM
Okay, I think I understood the mechanics. Now, what is the problem? What do you mean by "overlapping"?
What I would do to move things in a 2D game is to have a two-dimensional int array (the field) which knows where the player and the obstacles are. For example 0 means it is empty, 1 means it is an obstacle, 2 the player.
Now I would create some Instances for my Obstacles and my Player (GameObjects with a script). When I tap for example, I can check which Obstacles or Player are in the tapped line, calculate where they need to go by checking if there are other objects in the way and call a Obstacle.move(int x, int y); function on the Obstacles and Player respectively to tell them where to go (they can lerp it nicely on their own Update functions). After that, just update your field array where it is needed.
Does that help or is there another problem?
Answer by Veerababu.g · Jan 05, 2016 at 04:59 AM
thanks again @ RyFridge am already did that what you said above.By using the above concept there is non uni sync between the player and obstacle.i mean player move with one speed and the obstacle move another speed . the only solution solution is whenever it is colliding make the obstacle as child.
my problem(overlapping) is solved .what i did is whenever it(obstacle) is colliding with the player am making it as a child to the player and am giving suitable position to the obstacle.
thanks,,,,