I have a path which will be on bottom of the screen where insects will walk. But my path is not a straight line, it have ups and down. So how can I my insects walk my jagged line? The black line is my path. I want my insects to follow the up and down parts and I would like to achieve this using box2d. Any help? I don't know from where tostart to make this work. I haven't yet started to code. How can I make a bodyDef in box2d for the picture path below?
I assume that with the word "path" you mean the ground represented in the image, otherwise you can ignore the rest of my answer ;)
My suggestion is to follow these steps:
Create a body definition for the ground image. I use PhysicsEditor (free trial) that automatically creates the body definition for an image. If your image is transparent the body definition will map pretty well the shape in the image. PhysicsEditor exports the body definition via .plist which can be easily loaded via code.
Create a body definition for your insects (as above).
In your code create a static body for the ground using the ground body definition.
Create a dynamic body for each insect using the definition made at bullet 2.
Add gravity.
Now you'll see your insects on the ground. If you drag them (using the Mouse Joint provided by box2d) you will see that they react realistically to the ground and do not intersect it.
Finally you need to apply a force (in box2d) in order to autonomously move the insects.
This is just an high-level description of the steps you should follow. More specific information for each step is provided by the PhysicEditor documentation and box2d documentation.
I hope that this is going to help you.
Related
please can i have a little help guidance in something, a about mesh curving , kind of look around but would like your advice
This object (the circle shape) is getting deformed like the yellow part, what do you advice me about it please?
Any script to see the mechanic or similar examples? (Attached gif)
I tried to see some but only works with mouse click ( I am very new to mesh binding )
Like What you watching here
thanks
I would start by describing the whole shape as list of points.
Then you should be able to move those points either via physics or "manually" (by doing Physics2D.OverlapPoint and some math during movement).
With that it's just a matter of constructing runtime mesh, there are tutorials on how to do that (I think Freya Holmér has one), just look for "procedular geometry" or similar.
In general I wanted to make it in unity3d but I saw that in tutorials, they made it in blender.
This is what I did in unity:
I want to make this high cube hollow on the inside, and make a small door so that I will be able to walk inside the cube. Later on, I want to somehow add stairs but the problem now is how to make it hollow on the inside.
I saw in some places the suggestion to use blender so I tried this tutorial in blender:
Blender
But got stuck there after I checked the Add Mesh Extra Objects and clicked on Save User Settings. I tried then to click on the bottom on Add > Mesh but then I don't have Extra Objects. I have Extras objects like in the tutorial video.
Anyone my main goal is to make the high cube hollow on the inside with a small door on the bottom so I will be able to walk inside.
From what I know Unity3D has no 3DModelling by default (maybe there is something for that in store), so you need to use Blender or some other program (for example Maya). There is https://blender.stackexchange.com/ where you can ask same question (since it is not really unity3d related)
Maybe this will be helpful : https://blender.stackexchange.com/questions/5849/how-do-i-create-a-solid-object-cube
Overall what you could do, but it is not the est way - you can build a everything out of boxes yourself in Unity3D
Try use to boolean modifier. Take a look this tutorial:
Blender 2.6 Tutorial 26 - Boolean Modifier
I'm trying to do some Augmented Reality in Unity using the Vuforia plugin. I've managed to get everything working (I'm using a 3d model of a car), only the position of the car relative to the marker is wrong when I come to preview it (click the 'Play button at the top and watch through the computer's camera - is 'preview' the right name for this?).
It should be sitting on the the marker in the center, but instead it's floating above the marker and off to the side by quite a bit. The positioning is definitely right in the program itself, so I'm not sure why this isn't reflected in the preview.
Also: at the moment the car is simply an untextured grey object. I realise the textures are included in a subfolder, however I can't drag the entire car's folder (including the Textures subfolder) into the ImageTarget, only the .3ds file itself. Does anyone know how to apply the original textures to the car?
Thanks so much for your help in advance!
Ben
Well, to start answering your question about the drifting away part, you've probably got a Rigidbody attached to your Car? Well, if that's the case, then Go to the Inspector where the Rigidbody is and you'll see constraints.
To avoid it floating off, you might want to check Freeze Positions for whichever direction it needs. Probably Y axis.
Now, I'm not entirely sure if you're using Vector.AddForce to move your objects, but if you are then just check if your car can move if you've put all constraints on.
If you can't then in your code trying using Object.Rigidbody.SetActive(true) when you need it to start moving, and Object.Rigidbody.SetActive(false) when its done.
On the other hand, if you aren't using Vector.AddForce() then remove Rigidbody component if you've used it.
As for the material. If you've got the material in your folder that you've downloaded then just drag and drop it into Assets. Now sometimes your car may be one solid mesh, but some times it may be multiple meshes. So which ever the case. Drag the material from your Assets onto the Hierarchy panel over your car mesh/meshes and it should turn into that color.
Hope it helps. :)
I'm new to Unity3D, after several official tutorials I got some basic understanding about Unity3D. Now I would like to have fun with making my game.
I would like to have a sword cut an avatar into pieces. Like the game "Fruit Ninja", cutting fruit into pieces.
The specific effect I want: the cutting should be according to sword-cutting-angle, in other words, the breaking-pieces effect should vary according to every cut, that feels real.
My thought: since Avatar is made by Mesh Filter, if I cut the avatar by waist, into two pieces(upper body, lower body), I should use code to make two Mesh Filter to hold the two pieces.
I'm not expecting very detailed code, that could be a lot. I'm just wondering if I could get a clue about how to make this effect. Because I think "cutting avatar into piece" should be a general effect in game.
Thank you in advance :)
It's not easy as you may think...
Here you can get one approach to the solution:
it clones the object, finds a plane based on user variables, and flattens all the points on the other side of the plane onto it, then repeats this with the clone and the other side of the plane.
Other approach could come from using shaders, search for "cut away view shader".
I hope I have given you the start kick
I'm attempting to build a Lunar Lander style game on the iPhone. I've got Cocos2D and I'm going to use Box2D. I'm wondering what the best way is to build the floor for the game. I need to be able to create both the visual aspect of the floor and the data for the physics engine.
Oh, did I mention I'm terrible at graphics editing?
I haven't used Box2D before (but I have used other 2D physics engines), so I can give you a general answer but not a Box2D-specific answer. You can easily just use a single static (stationary) Box if you want a flat plane as the floor. If you want a more complicated lunar surface (lots of craters, the sea of tranquility, whatever), you can construct it by creating a variety of different physics objects - boxes will almost always do the trick. You just want to make sure that all your boxes are static. If you do that, they won't move at all (which you don't want, of course) and they can overlap without and problems (to simulate a single surface).
Making an image to match your collision data is also easy. Effectively what you need to do is just draw a single image that more or less matches where you placed boxes. Leave any spots that don't have boxes transparent in your image. Then draw it at the bottom of the screen. No problem.
The method I ended up going with (you can see from my other questions) is to dynamically create the floor at runtime and then draw it to the screen.