_id
int64 0
49
| text
stringlengths 71
4.19k
|
---|---|
21 | Where does the game code fit into the engine? I was wondering if somebody could tell me how the game and the game engine fit into game development. What I specifically mean is, the game engine does not actually contain a game. Do game developers build an engine, then create a new class that inherits from the engine, which becomes the game? For example, class ShooterGame public Engine I'm not sure about where the game code fits into the engine. |
21 | Why are there fewer glitches in current day games? I remember that almost every single game in the early 2000s had at least a few amusing glitches, mostly related to animations, that often produced funny situations. I also remember that game magazines used to dedicate a section with the funniest screenshots people sent in. As an example, I was just playing Far Cry from 2004 and out of nowhere, whenever I killed some bad guy, instead of dropping to the ground they'd start playing the running animation. This was getting me confused since I was trying to shoot them down from a large distance and didn't understand why they weren't dying. I've rarely seen stuff like this in current day games. Was there some change in the technique used to develop games that would make these programmer mistakes less likely? P.S. I'm not talking about RPGs and other inherently complex genres. I'm talking about games like Far Cry shooters like Battlefield 3, Modern Warfare 3, even Mass Effect. I've seen plenty of glitches in games like The Witcher 2, Skyrim, etc. |
21 | Creating VR Headset Video So I have a video stream of known resolution and I have a VR headset via HDMI at a known resolution. Is there an existing library to create the slight fisheye and side by side layout for these single screen headsets? (It's a custom build, so no hardware locked API please) Target Win 7 8 10 |
21 | Effects for Programmers Does anyone have any good resources for creating special effects, aimed at programmers. I'm not specifically interested in particle effects, but broader things like Fullscreen effects, blur, depth of field, damage Explosions, shockwaves Weapons, lasers, projectile Environment light "glows" and beams, water, bubbles, dust etc I'm interested in these things from a technical perspective rather than an artistic one. EDIT To clarify, I'm not interested in the low level details like "a method for doing depth peeling on SPUs" or "fast particle rendering with vertex textures", I'm interested in how people have combined various techniques into a recipe to show a special effect for the game. For example when rendering a "space" explosion Draw opaque bright sphere at center. Draw alpha'd shockwave around a random axis. Expand sphere and decrease alpha. Expand shockwave and rotate UVs. Spawn particles showering randomly from center. Wobble camera when shockwave reaches viewer position. |
21 | What are windows used for? I have a very general question In games, what use does the programming concept of a window have? Or, in other words, why do some game dev libraries offer interfaces through which to create multiple windows? mdash Why would you need more than one windows in a game? Are multiple windows used as different views states of the game? (I.e. in game, main menu, pause menu, etc.) |
21 | Programmatically drawing a "pencil" line or curve If you look closely (scan it on a computer and zoon in) at a carbon pencil line you can see that there are differing shades of gray. I tried looking on the Internet for any kind of algorithm or statistical model for how that gray would be drawn programatically. Does anyone have information on this? Thanks a lot!! I want to make drawings on a computer that look they were drawn with a pencil. |
22 | coloring box2d body in LibGDX I want to color polygon of box2d in LibGDX. Found below useful class for that. http libgdx.badlogicgames.com nightlies docs api com badlogic gdx graphics glutils ShapeRenderer.html But, it is not coloring the body instead making colored shapes. I want colored bodies having all the property like gravity, restitution etc. In brief, I want to make colored ball and surface.And i don't want to attach sprite on bodies. Want just fill color in bodies. Need some guidance???? |
22 | What scaling system to use in Box2d? I'm worried about this Caution box from the Box2d manual Box2D is tuned for MKS units. Keep the size of moving objects roughly between 0.1 and 10 meters. You'll need to use some scaling system when you render your environment and actors. The Box2D testbed does this by using an OpenGL viewport transform. DO NOT USE PIXELS. I don't want to use OpenGL since I know nothing about it. I'm using SFML to render my game. |
22 | Is it a good idea to use box2d to control sprite movement in a 2D game? I'm trying to use Box2D to control sprite movement.Some burning issues are these 1.When I trying to move the sprite on a slope or a lean barrier. The sprite will move off the slope which is not what I want. 2.ALternatively, I could use setPosition or CCAction which provides by cocos2d x to move the sprite and update the body position use SetTransform. But the body will lost it's physical limitation, it will passthrough other body. Thanks for your time, if you guys got any solution? |
22 | Box2d How to connect distance joint to the ground? I have a rectangular fixed size world. I want to connect a body inside it to any place(near that body) in the world with a b2DistanceJoint. Do I need to create a large static body with the size of the world that can't collide with anything? Or is there a better method? Will it slow down simulation speed if I have around 300 bodies moving on the surface of this static body? |
22 | Rotate Body From Corner I want to ask that how to rotate body from corner? movableBeam.getBeamBody().setTransform(movableBeam.getBeamBody().getPosition(), angle) The above line of code rotate the beam from center that I want rotate from one of the conner. Any member please help me. EDIT float beamCenterX movableBeam.getX() movableBeam.getWidth() 2f float beamCenterY movableBeam.getY() movableBeam.getHeight() 2f float cornerOffsetX movableBeam.getX() beamCenterX float cornerOffsetY movableBeam.getY() beamCenterY float bodyAngle (float) Math.atan2(cornerOffsetY, cornerOffsetX) float newAngle imageAngle bodyAngle float newCornerOffsetX (float) Math.cos(Math .toDegrees(newAngle)) float newCornerOffsetY (float) Math.sin(Math .toDegrees(newAngle)) cornerOffsetX movableBeam.getX() movableBeam.getWidth() 2f cornerOffsetY movableBeam.getY() movableBeam.getHeight() 2f Vector2 postion new Vector2( (newCornerOffsetX cornerOffsetX movableBeam.getX()) PhysicsConstants.PIXEL TO METER RATIO DEFAULT, (newCornerOffsetY cornerOffsetY movableBeam.getY()) PhysicsConstants.PIXEL TO METER RATIO DEFAULT) movableBeam.getBeamBody().setTransform(postion, newAngle) |
22 | What is inertia in a physics engine? Inertia seems to be useful in a physics engine, so useful that even in Box2DLite, a demo of Box2D it hasn't been omitted. See this Body class from Box2DLite struct Body Body() void Set(const Vec2 amp w, float m) void AddForce(const Vec2 amp f) force f Vec2 position float rotation Vec2 velocity float angularVelocity Vec2 force float torque Vec2 width float friction float mass, invMass float I, invI inertia and reverse inertia In the implementation of the class, inertia is set as the mass multipled by something I mass (width.x width.x width.y width.y) 12.0f invI 1.0f I What does this formula means ? I understood from wikipedia that Inertia is how much something doesn't want to move but there's not much formulas in this article. Why is it useful in a physics engine ? How is it used in the context of a collision ? Is it compared to other bodies ? |
22 | How to keep the value of angle between 0 and PI in box2d In box2d, if i rotate an object multiple times in clockwise or anti clockwise direction, the value of angle ( body.getAngle() ) keeps on increasing. Like at start it is at 0 radians, then 1.57(90 deg), after complete roatation 6.28, then after second rotation 2 6.28 . If a player keeps on rotating for too much time, angle value becomes really big.And for multiplayer games, sending big values uses more bytes. How can i keep the value between 0 to 3.14.Is there any solution in box2d Or Is it a good way of sending Sin(angle) to keep the value between 1 and 1 and doing reverse of sin at client side. |
22 | How to make box2d bodies block each other but not push each other? I want to use box2D to create a movement system for an RTS game. How can I make bodies block the movement of other bodies while preventing these bodies from pushing each other? |
22 | How to simulate a water splash effect? I need to achieve the effect of a ball falling down into a pool then splashing in the water. At first, I made a sensor to detect the collision between the ball and the water and then show the sprite of the spray. But it's hard to change the sprite according to the velocity of the ball and the angle between the ball and pool. So, I want to simulate the physical model of the water. Now, what I can do is to add a particle system using Cocos2D to show the still water and add physical model to each particle. But, I don't think it is a good solution. Any other I can do it? Waiting for you help. |
22 | How to apply impulse to a body to make it fly away? I'm playing around with jbox2d and can't really make a body "fly away" as if from an explosion. From what I have found on the net, making the body fly away from the world center (0,0), should have been something like that b.applyLinearImpulse( new Vec2(0,0) , b.getPosition() ) But really it just doesn't do anything, any idea why? Also how do I change the strength of the impulse, like if it want to make it fly skyhigh or just move a bit? |
22 | How to simulate feather fall in box2d? I am working with AndEngine with Box2d extension, but general answer or a concept idea will be appreciated too. I have feather like objects in a 2D side view world that I want to be part of the physics simulation. I am using linear damping to make the "feather" fall slowly. This might not be a good idea, maybe I should rather apply force in each update, but nevertheless, this works and it makes the object look "light" and it feels like there is air with resistance. Now how can I make the objects actually look like feathers falling through air? Specifically I am looking for two types of objects Long with low density, that should move down in a slow swinging motion and square objects that would just randomly change trajectory. It would be great if this could be one simulation and length would be a parameter the longer the object is, the more it would swing. Right now I want to simulate feathers, leaves and snowflakes in a cartoon world. |
22 | Problem with sensor in box2d I have two bodies one green static sensor (spikes) and one orange dynamic body (brick). I have bullet and it's a dynamic body too, but with bullet flag set. My problem is that when the bullet is moving left to right, it sometimes hits the orange brick instead of the spikes and it flies away. There is code to remove the bullet when it hits spikes. How can I make sure it hits the spikes first? |
22 | Dynamic body in Box2D with fixed position I need to fix the dynamic body position so that it would not rotate and would not move even if there are other forces, collisions and so on. Let me first explain why I need this. I have a dynamic body which is the game character. There are non moving objects that the game character should land on and get some energy as long the character is in contact with those bodies. As these bodies are non moving it would be natural to make them Static or Kinematic. But in my case I cannot do that, as far as there is another Kinematic body with which all the game items should be collided and on EndCollision event those items should be removed. But in Box2D static and kinematic bodies don't collided with each other. So I have to make my game item on which the character should land Dynamic but still should be sure that it will not move. How should I do this? |
22 | How to simulate feather fall in box2d? I am working with AndEngine with Box2d extension, but general answer or a concept idea will be appreciated too. I have feather like objects in a 2D side view world that I want to be part of the physics simulation. I am using linear damping to make the "feather" fall slowly. This might not be a good idea, maybe I should rather apply force in each update, but nevertheless, this works and it makes the object look "light" and it feels like there is air with resistance. Now how can I make the objects actually look like feathers falling through air? Specifically I am looking for two types of objects Long with low density, that should move down in a slow swinging motion and square objects that would just randomly change trajectory. It would be great if this could be one simulation and length would be a parameter the longer the object is, the more it would swing. Right now I want to simulate feathers, leaves and snowflakes in a cartoon world. |
22 | GetContactList stops reporting collisions on welded bodies I have some strange problem with my game which uses Box2D as physics engine and I'm out of ideas on what I can do to solve it. My game is a class assignment where I need to build a simple game where the main character moves in a 2D environment while square blocks comes from below him. Each time a collision occurs, that block is attached to the character using a weld joint, when three blocks of the same colors are together, they annihilate themselves(an effect similar to Bejeweled). I'm using a recursive function to iterate through all the attached blocks of a given block to see if there are enough blocks for them to be deleted. I'm using GetContactList function to iterate through the list of contacts to see which blocks are adjacent to each other. The results are quite disappointing, the blocks only get annihilated in few cases. After a lot of debugging, I found the issue, but I still don't know how to solve. My issue is after some time, GetContactList STOPS returning contacts (return NULL) to blocks that were already attached for some time. I spent some time reading the Box2D manual as well as some tutorials and still didn't find any clue of what is happening. Below there's some simplified version of the code that I wrote. for(int a 0 a lt blocksList.size() a ) blocksList a .BuildConnections() And on BuildConnections b2ContactEdge edge body gt GetContactList() while(edge ! NULL) if (long check to see if there's a block nearby) add itself to the list to be anihilated globalList.push back(this) if there's, call BuildConnections again on the adjacent block adjacentBody gt GetUserData() gt BuildConnections edge edge gt next I know that there's another issue related to circular inclusions, but I fairly sure that this problem isn't causing the problem with the collisions. You can download my entire code from this page if you'd like http code.google.com p fellz source list |
22 | Box2d pathfinding using raytracing predicted collisions I have a Box2d Cocos2d iOS game with enemies that attempt to follow the player (to attack). I'm working on improving the pathfinding logic so that the enemies won't crash into objects in the world. Using raytracing, I know when there's an obstacle between an enemy and the player. I know when the enemy can't see the player. I'm attempting to find a good way for the enemy to navigate around the obstacle, no matter what direction it's facing. Right now, I start with the angle between the enemy and the obstacle. I gradually increment the angle, looking for any on obstructed path that will allow the enemy to travel further than the obstacle's distance. This seems to work well so far, but it doesn't take into account the size of the enemy. For example, if I have a 32px squared enemy, the raytrace may find a clear path that would involve the edges of the ship hitting an obstacle. Is there a way I can run a raytrace, predict collisions for something with a known width? Or is there a better way for my enemies to navigate around an obstacle. |
22 | Libgdx explain steps for beginner to create and use image as a box2d body I am basically from corona background and new to LibGdx , familiar with stage and actor from scene2D. Now wants to use physics body from box2d in the game besides using actor from scene2D. But I need to use images in the game as body... not shapes.. anyone please explain me the steps to use images as a body. Thanks.. |
22 | Is it easy to switch from Chipmunk to Box2D? Currently I'm doing some prototyping with physics in Python and I later plan to port the code over to C . Box2D has some features that I really like so I'd rather use that library instead. The problem is that the Python port of Box2D is pretty tedious to install and I'm lazy, D while the Chipmunk port is very easy to install. Is it hard for me to switch libraries later on when I port the code to C ? (Will I have to do big architectural changes?) |
22 | How to use the testbed with box2dflash? I have made games with box2dflash, but how much ever i have wanted to try out the test bed, the resources on the net don't help me. I have a folder called Testbed and various Test???.as files inside it. It would be a great help if somebody could just jot down how the testing of a box2dflash game is done. Thank you |
22 | Box2D body jitters when colliding with static body I am developing a game where a body is moved within the scene using touch. The scene has a boundary wall made up of static rectangular bodies. When I move the object along the boundaries, on collision, it jitters. This is because the boundary wall pushes the body outwards while the touch pushes it against the wall. I am using linear velocity to move the body using touch. I tried to avoid this by setting the linear velocity of the body to 0 on collision with the boundary wall but it didn't work. I am trying to have a smooth movement along the boundary walls with no jitters. How can I solve this? Following snippet moves the body on touch. Linear velocity vector has direction towards the touch point. The movement is smooth within the play area but not at the boundaries. case TouchEvent.ACTION MOVE strikerBody.setLinearVelocity((pSceneTouchEvent.getX() body.getPosition().x PIXEL TO METER RATIO DEFAULT),(pSceneTouchEvent.getY() body.getPosition().y PIXEL TO METER RATIO DEFAULT)) These are the bounadry walls final Rectangle groundLeft new Rectangle(camera.getWidth() 2 camera.getWidth() 4, 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle groundRight new Rectangle(camera.getWidth() 2 camera.getWidth() 4, 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle roofLeft new Rectangle(camera.getWidth() 2 camera.getWidth() 4, camera.getHeight() 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle roofRight new Rectangle(camera.getWidth() 2 camera.getWidth() 4, camera.getHeight() 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle leftTop new Rectangle(1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16 , 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final Rectangle leftBottom new Rectangle(1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16, 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final Rectangle rightTop new Rectangle(camera.getWidth() 1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16, 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final Rectangle rightBottom new Rectangle(camera.getWidth() 1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16, 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final FixtureDef wallFixtureDef PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f) PhysicsFactory.createBoxBody(this.mPhysicsWorld, groundLeft, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, groundRight, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, roofLeft, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, roofRight, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, leftTop, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, leftBottom, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, rightTop, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, rightBottom, BodyType.StaticBody, wallFixtureDef).setUserData("wall") this.attachChild(groundLeft) this.attachChild(groundRight) this.attachChild(roofLeft) this.attachChild(roofRight) this.attachChild(leftTop) this.attachChild(leftBottom) this.attachChild(rightTop) this.attachChild(rightBottom) |
22 | Get Vertices of a Shape Body in Box2D Is there a way to do it? I can get only polygon shape's vertices, but i want circle, box, etc too. How to do it? |
22 | Getting Bodies to go "Super Fast" in Box2D I am making a breakout game in Android using the LibGDX version of Box2D. I have a ball that I am applying a force to with the following code... getBody().applyForceToCenter( 10000000000.0f, 10000000000.0f) This makes the ball move properly, but it never seems to gain a lot of speed (and I want to make it go super fast). I tried adding an accelerate method where I applied the force 40 times, but again it doesn't seem to move that fast. What is a good way to make a Body go "Super fast" in Box2D? If there is acceleration I would like it to be as short as possible. I tried adding the following.... World.setVelocityThreshold(1000000.0f) But now the ball doesn't seem to "bounce" off walls, do I need to raise my restitution or something? |
22 | How do I duplicate a Box2d simulation, mid simulation? I want to serialize the state mid game, send it over the network to an identical computer (same CPU, same OS, same binary), load it there, and have the two games run in tandem doing the exact same simulation, without one of them drifting off and going haywire. In short I want pop in, pop out networking support on my HIGHLY physics intensive game, where sending object coordinates every few seconds is impossible, due to having thousands of objects, and many clients. I tried this with Box2D, and saving an object's location velocity etc wasn't enough... there's internal state that's not accessible through any public methods. My current workaround is to force EVERY client to save its entire worldstate and reload it from scratch, whenever a new player connects... but this is obviously bad practice, because it hangs the game for everyone whenever someone new connects. However, it works, with zero desynchronization. So, anyone know of any other techniques that can help me? Or should I just kiss my project goodbye? |
22 | How do I copy box2d data from one body to another? I want to copy all Box2D related data (position, velocity, rotation, impulse, ...) from one body to another. This is what I've got working (with box2djsweb) var t body.GetTransform() other body.SetTransform(t) var vel body.GetLinearVelocity() other body.SetLinearVelocity(vel) I think that covers most things, but judging by the behaviour, I've missed something. It's as if it's a frame or tick behind. Also, this isn't placing the other body in the exact location as the the original body. Is there a better way to do this? |
22 | Ring and Pole Box2d How I can make a b2Body in box2d so that it could form a ring which does not collide from the center just like a ring. like when we flick the object and there's another body (like pole), the pole can go inside from the ring. like this |
22 | Change the shape of body dynamically I have a problem where i have a ballon which i need to continuously inflate and defalte in update method, I have tried to used setScaleCenter but it is not giving desired result. Below is a code i am trying to make work scale (float) ((dist lastDist) lastDist) Log.d("pinch","scale is " scale) Log.d("pinch","change in scale is " (float) ((lastDist dist) lastDist)) player.setScaleCenter(scale, scale) player.setScale(scale) |
22 | Making a physics body so that another body passes through Basically I "think" I want a static body that does not have any density so another body can "pass through it" without getting slowed down. I tried this and it doesn't seem to work. What would be the proper way to do this? Any version (C,C , Java) would be fine for an answer. |
22 | Box2D Farseer Collision Detection I am looking for literature or a simple explanation on how the Farseer (and for that reason, the Box2D) collision detection system works specifically the logic that comes after the broadphase culling What data structure does it use? How does it use that data structure to determine if a collision has occurred? How does it calculate the response normals? NB I am not asking how to use it, I merely want to know how it works as a matter of personal enlightenment. |
22 | Box2D Farseer Collision Detection I am looking for literature or a simple explanation on how the Farseer (and for that reason, the Box2D) collision detection system works specifically the logic that comes after the broadphase culling What data structure does it use? How does it use that data structure to determine if a collision has occurred? How does it calculate the response normals? NB I am not asking how to use it, I merely want to know how it works as a matter of personal enlightenment. |
22 | Box2d What is the best approach to build static Box2d smooth curve line i want to know what is the best approach to simulate smooth curved line as static body it will be like path for car to drive . something like this http www.freeriderhd.com how does its box2d static body are constructed ? Thanks |
22 | How do I copy box2d data from one body to another? I want to copy all Box2D related data (position, velocity, rotation, impulse, ...) from one body to another. This is what I've got working (with box2djsweb) var t body.GetTransform() other body.SetTransform(t) var vel body.GetLinearVelocity() other body.SetLinearVelocity(vel) I think that covers most things, but judging by the behaviour, I've missed something. It's as if it's a frame or tick behind. Also, this isn't placing the other body in the exact location as the the original body. Is there a better way to do this? |
22 | Libgdx explain steps for beginner to create and use image as a box2d body I am basically from corona background and new to LibGdx , familiar with stage and actor from scene2D. Now wants to use physics body from box2d in the game besides using actor from scene2D. But I need to use images in the game as body... not shapes.. anyone please explain me the steps to use images as a body. Thanks.. |
22 | In Box2D, what exactly does a fixture represent? In Box2dWeb, when we create a body we attach a fixture to the body object. We make the shape, friction, restitution and so on by tinkering with the fixture object. So from this can we conclude that the fixture is what we really need to tinker with to get the body we want, and the body object we create just an abstract entity? Abstract in the sense that by itself, it is invisible in the canvas after we draw and animate the canvas? The body is just the abstract, formless object that becomes physical once we attach the fixture. Is this right to conclude? |
22 | Making the player walk on walls in box2d I'm making a game in stencil where players walk form left to right along randomly generated walls. I cant use waypoints, since the walls' shapes and positions are unpredictable. Here's a descriptive sketch The red line is the player's path. The red circles are what I thought might make good waypoints until I scrapped the idea. |
22 | Unable to find good parameters for behavior of a puck in Farseer EDIT I have tried all kinds of variations now. The last one was to adjust the linear velocity in each step newVel oldVel 0.9f all of this including your proposals kind of work, however in the end if the velocity is little enough, the puck sticks to the wall and slides either vertically or horizontally. I can't get rid of this behavior. I want it to bounce, no matter how slow it is. Retitution is 1 for all objects, Friction is 0 for all. There is no gravity. What am I possibly doing wrong? In my battle to learn and understand Farseer I'm trying to setup a simple Air Hockey like table with a puck on it. The table's border body is made up from Vertices aBorders new Vertices( 4 ) aBorders.Add( new Vector2( fHalfWidth, fHalfHeight ) ) aBorders.Add( new Vector2( fHalfWidth, fHalfHeight ) ) aBorders.Add( new Vector2( fHalfWidth, fHalfHeight ) ) aBorders.Add( new Vector2( fHalfWidth, fHalfHeight ) ) FixtureFactory.AttachLoopShape( aBorders, this ) this.CollisionCategories Category.All this.CollidesWith Category.All this.Position Vector2.Zero this.Restitution 1f this.Friction 0f The puck body is defined with FixtureFactory.AttachCircle( DIAMETER PHYSIC UNITS 2f, 0.5f, this ) this.Restitution 0.1f this.Friction 0.5f this.BodyType FarseerPhysics.Dynamics.BodyType.Dynamic this.LinearDamping 0.5f this.Mass 0.2f I'm applying a linear force to the puck this.oPuck.ApplyLinearImpulse( new Vector2( 1f, 1f ) ) The problem is that the puck and the walls appear to be sticky. This means that the puck's velocity drops to zero to quickly below a certain velocity. The puck gets reflected by the walls a couple of times and then just sticks to the left wall and continues sliding downwards the left wall. This looks very unrealistic. What I'm really looking for is that a puck wall collision does slow down the puck only a tiny little bit. After tweaking all values left and right I was wondering if I'm doing something wrong. Maybe some expert can comment on the parameters? |
22 | Box2d Is there a way to have collisions but ignore the accompanying forces? To begin, I know that you can use filtering or isSensor to remove physical collisions. However, I would like to retain the ability to, say for example, stop when trying to move past another player. Essentially, I don't want one player to be able to push another dynamic body with the force that normally accompanies a collision. I've tried static and kinematic bodies, but both obviously have their own problems with trying to have collisions. An example might be a topdown game such as League of Legends of Starcraft, where units can impede on eachother's movements, but don't apply any force upon collision. |
22 | how can i move static box2d object how can i move static box2d sprites. i have tried this tutorial from . http www.raywenderlich.com 475 how to create a simple breakout game with box2d and cocos2d tutorial part 12. I managed to add another "paddle" object with box2d body, but i can seam to be able to make the code to move the second "paddle" body. Can anyone direct me how to do it? Is there a way to move a "b2 staticBody" box 2d object? i have tried, but i can only move it when i use "b2 dynamicBody" if i used "b2 staticBody" i can move it at all. |
22 | Stopping on a slope in Box2d I am creating a simple platformer using Box2d. I've implemented a variant of the technique described here. To make the player character move more 'platformer like' I want him to stop on (shallow) slopes. However, the engine I am using does not support angle joints, so I have trouble restricting the movement of the wheel. I've tried some different alternatives that not worked Setting the horizontal velocity to 0 every game loop doesn't seem to work, because between calls the wheel catches up speed once again. Is there another way to fix this? |
22 | How to apply impulse to a body to make it fly away? I'm playing around with jbox2d and can't really make a body "fly away" as if from an explosion. From what I have found on the net, making the body fly away from the world center (0,0), should have been something like that b.applyLinearImpulse( new Vec2(0,0) , b.getPosition() ) But really it just doesn't do anything, any idea why? Also how do I change the strength of the impulse, like if it want to make it fly skyhigh or just move a bit? |
22 | Errors happen when using World.destroyBody( Body body ) on Android application using libgdx, when I use World.destroyBody( Body body ) method, once in a while the application suddenly shuts down. Is there some setting I need to do with body collision or Box2DDebugRenderer before I destroy bodies? Below is the source I use for destroying bodies. private void deleteUnusedObject( ) for( Iterator lt Body gt iter mWorld.getBodies() iter.hasNext() ) Body body iter.next( ) if( body.getUserData( ) ! null ) Box2DUserData data (Box2DUserData) body.getUserData( ) if( ! data.getActFlag() ) if( body ! null ) mWorld.destroyBody( body ) Thanks |
22 | What is inertia in a physics engine? Inertia seems to be useful in a physics engine, so useful that even in Box2DLite, a demo of Box2D it hasn't been omitted. See this Body class from Box2DLite struct Body Body() void Set(const Vec2 amp w, float m) void AddForce(const Vec2 amp f) force f Vec2 position float rotation Vec2 velocity float angularVelocity Vec2 force float torque Vec2 width float friction float mass, invMass float I, invI inertia and reverse inertia In the implementation of the class, inertia is set as the mass multipled by something I mass (width.x width.x width.y width.y) 12.0f invI 1.0f I What does this formula means ? I understood from wikipedia that Inertia is how much something doesn't want to move but there's not much formulas in this article. Why is it useful in a physics engine ? How is it used in the context of a collision ? Is it compared to other bodies ? |
22 | Reduce bounciness of dynamic bodies in Box2D In my 2D platformer game my player character is modeled using a Box2D dynamic body. One thing I thought feels off though is that even though the restitution of the fixture applied is zero, the player will bounce off static geometry when falling at an angle, kind of like a plastic box would perhaps, but certainly not like a body would. There isn't really much that Box2D allows me to tweak though except for density and restitution? I noticed that playing with the density has basically no effect on how the player moves which I thought was odd too. Are there any realistic value ranges you would recommend? It's all a bit trial and error right now for me. |
22 | How to move a b2Body explosively to a new Location I am building an Game based on Box2d with the following basic structure The Box2d World itself does not have any Gravity and is filled with some bodies (sheres and simple polygons) of more or less the same size. The user can select on of them and if he clicks on the free space, the selected body should be moved onto the "point of click". The movement should be explosive, what the use of b2Body.ApplyImpulse suggests, but also stop quickly when the point is reached. This leads me to two problems Which method should i use ApplyImpulse or ApplyForce? How could I calculate the right vector of the impulse, if you would use this method? How could I correct the body's way if it collides with another? Greetings Philipp |
22 | Scaling bodies in box2d and libgdx Is there a way to scale the bodies made from vertexes (like a guitar), i was trying to multiply each vertex point by the scale value but c mark an assertion failed, is there a mehtod to do this? I have done it, but i want to make a mirror body, but i cant do it just multplying it by 1 or 1 it doesnt run |
22 | cocos2d Merging box2d bodies i'm using cocos2d to build an iphone game. my game currently has two sprites one for the main character and another for an item i should carry once he gets on him. the main character and the item are both box2d bodies. i can detect the collision between the two. what is want is to make the item body stick to the main character body when they meet, that way any movement of the main character would also affect the item. any suggestions on how to implement this? thanks! |
22 | Relative movement in Box2D (keep object from falling off planet) I'm creating a game with planets orbiting around a sun, like this The brown square is the earth, rotating around its center and around the sun. The yellow square is the sun, which doesn't move. Now imagine a player standing on the planet, the planet moves at a velocity of 20 m s. How do I prevent the player from falling off? I have to give the perception to the player that the planet isn't moving. I got the gravity on earth working, but I don't know how I can keep the player on the planet! I have thought about two solutions until now Just apply the angular velocity and linear velocity of the planet on the player (if it's in a specified radius), I think this method will cause jittery movement glitches. Create a separate Box2D world for the planet and render this Box2D world with the rotation translation of the planet. This method is complex though since it would add the problem of moving bodies between different worlds if the player would leave the planet. This image explains it I think there is another (better) way to fix this problem, but I haven't found a solution yet. |
22 | Explain the difference between extrapolation and interpolation http www.unagames.com blog daniele 2010 06 fixed time step implementation box2d here there are two algorithms of smoothing in case of fixed time step physics simulation. I don't understand the formula of interpolation state currentState alpha previousState (1 alpha) And also I don't understand the comparison figure. Please explaing what is the meaning of multiplying current state with alpha and summing with previous state with 1 alpha. |
22 | Starter love2d physics program not working I am starting out with my first love2d (using L VE 0.8) physics program. I am just creating some ground floor, a car body and attaching two wheels with revolute joints and setting the motors a go. However, the car stands still, whereas I expect it to move. Can someone glance over the code below and see what I am doing wrong? UPDATE See below! function love.load() Set up world love.physics.setMeter(50) world love.physics.newWorld(0, 9.81 50, true) Window dimensions windim height love.graphics.getHeight(), width love.graphics.getWidth() objects Ground Floor objects.ground objects.ground.body love.physics.newBody(world, 300, windim.height) objects.ground.shape love.physics.newRectangleShape(2000,20) objects.ground.fixture love.physics.newFixture(objects.ground.body, objects.ground.shape) objects.ground.fixture setFriction(3) Body of the car a rectangle objects.carbody objects.carbody.body love.physics.newBody(world, 300, 500, "dynamic") objects.carbody.shape love.physics.newRectangleShape(100,40) objects.carbody.fixture love.physics.newFixture(objects.carbody.body, objects.carbody.shape) objects.carbody.fixture setFriction(3) objects.carbody.fixture setDensity(3) objects.carbody.fixture setRestitution(0) First wheel objects.wheel objects.wheel.body love.physics.newBody(world, 330, 520, "dynamic") objects.wheel.shape love.physics.newCircleShape(20) objects.wheel.fixture love.physics.newFixture(objects.wheel.body, objects.wheel.shape) objects.wheel.fixture setFriction(3) objects.wheel.fixture setDensity(3) objects.wheel.fixture setRestitution(0.6) Second wheel objects.wheel2 objects.wheel2.body love.physics.newBody(world, 270, 520, "dynamic") objects.wheel2.shape love.physics.newCircleShape(20) objects.wheel2.fixture love.physics.newFixture(objects.wheel2.body, objects.wheel2.shape) objects.wheel2.fixture setFriction(3) objects.wheel2.fixture setDensity(3) objects.wheel2.fixture setRestitution(0.6) Create joint between car body and first wheel objects.carbody.wheeljoint1 love.physics.newRevoluteJoint(objects.carbody.body, objects.wheel.body, 330, 520) objects.carbody.wheeljoint1 enableMotor() objects.carbody.wheeljoint1 setMaxMotorTorque(10000) Following example from http www.emanueleferonato.com 2011 08 22 step by step creation of a box2d cartruck with motors and shocks Create joint between car body and second wheel objects.carbody.wheeljoint2 love.physics.newRevoluteJoint(objects.carbody.body, objects.wheel2.body, 270, 520) objects.carbody.wheeljoint2 enableMotor() objects.carbody.wheeljoint2 setMaxMotorTorque(10000) end function love.update(dt) Set contstant speed for the wheels objects.carbody.wheeljoint1 setMotorSpeed(20) objects.carbody.wheeljoint2 setMotorSpeed(20) world update(dt) end function love.draw() love.graphics.print(objects.carbody.wheeljoint1 getMotorSpeed(), 10, 10) Render ground love.graphics.setColor(72, 160, 14) love.graphics.polygon("fill", objects.ground.body getWorldPoints(objects.ground.shape getPoints())) Render car body love.graphics.setColor(72, 160, 200) love.graphics.polygon("fill", objects.carbody.body getWorldPoints(objects.carbody.shape getPoints())) Render wheels love.graphics.setColor(193, 47, 14) love.graphics.circle("line", objects.wheel.body getX(), objects.wheel.body getY(), objects.wheel.shape getRadius()) love.graphics.circle("line", objects.wheel2.body getX(), objects.wheel2.body getY(), objects.wheel2.shape getRadius()) end UPDATE I added a line to print the angle of one of the wheels (see below). When this line is present, suddenly the car flips over from the wheels spinning when it hits the ground. This leads me to believe that something did not get initialized properly first time around. This is the line added function love.draw() love.graphics.print(objects.wheel.body getAngle(), 10, 10) Line added |
22 | Make player to always move along the terrain I'm working on a 2D platformer side scroller game. I am giving high impulse to player, the player starts moving and if it hits a slope on terrain, it gets a vertical movement and starts to fly over (Box2D physics). What I need is that the player should always be on the terrain and move along the ground. I would like to know if it's possible using Box2D engine. |
22 | Cocos2D Box2D body that is movable by one type of object but not another I'm in the process of creating a simple platform game using Cocos2D 2.0 and Box2D. I'm trying to create a kind of crate object that cannot be moved by the player, but that can be moved by an elephant object. When the player runs up to the crate, it should stop him dead in his tracks (as if he is running into a static Box2D body). If the elephant runs into it it should get knocked out of the way (as if the elephant was running into a dynamic Box2D body of much smaller mass density). I can't use collision bitmask because of course I want collision to occur in both cases, I just want that collision to result in different things depending on which type of object is hitting the crate. Anyone have a hint as to how to make this work? Thanks in advance! |
22 | Box2D body jitters when colliding with static body I am developing a game where a body is moved within the scene using touch. The scene has a boundary wall made up of static rectangular bodies. When I move the object along the boundaries, on collision, it jitters. This is because the boundary wall pushes the body outwards while the touch pushes it against the wall. I am using linear velocity to move the body using touch. I tried to avoid this by setting the linear velocity of the body to 0 on collision with the boundary wall but it didn't work. I am trying to have a smooth movement along the boundary walls with no jitters. How can I solve this? Following snippet moves the body on touch. Linear velocity vector has direction towards the touch point. The movement is smooth within the play area but not at the boundaries. case TouchEvent.ACTION MOVE strikerBody.setLinearVelocity((pSceneTouchEvent.getX() body.getPosition().x PIXEL TO METER RATIO DEFAULT),(pSceneTouchEvent.getY() body.getPosition().y PIXEL TO METER RATIO DEFAULT)) These are the bounadry walls final Rectangle groundLeft new Rectangle(camera.getWidth() 2 camera.getWidth() 4, 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle groundRight new Rectangle(camera.getWidth() 2 camera.getWidth() 4, 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle roofLeft new Rectangle(camera.getWidth() 2 camera.getWidth() 4, camera.getHeight() 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle roofRight new Rectangle(camera.getWidth() 2 camera.getWidth() 4, camera.getHeight() 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle leftTop new Rectangle(1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16 , 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final Rectangle leftBottom new Rectangle(1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16, 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final Rectangle rightTop new Rectangle(camera.getWidth() 1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16, 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final Rectangle rightBottom new Rectangle(camera.getWidth() 1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16, 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final FixtureDef wallFixtureDef PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f) PhysicsFactory.createBoxBody(this.mPhysicsWorld, groundLeft, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, groundRight, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, roofLeft, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, roofRight, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, leftTop, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, leftBottom, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, rightTop, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, rightBottom, BodyType.StaticBody, wallFixtureDef).setUserData("wall") this.attachChild(groundLeft) this.attachChild(groundRight) this.attachChild(roofLeft) this.attachChild(roofRight) this.attachChild(leftTop) this.attachChild(leftBottom) this.attachChild(rightTop) this.attachChild(rightBottom) |
22 | Speed of bodies in Box2D and libgdx I want to move my bodies at higher speeds, but they have a top speed. I have an Ortoghraphic camera defined at 800x480. My world doesnt have gravity. I apply an impulse of 1000,and a force of 1000 too. But the speed always is at the same value, it doesnt have more. How do i add more speed to my body (its a dynamic body). |
22 | Box2D body jitters when colliding with static body I am developing a game where a body is moved within the scene using touch. The scene has a boundary wall made up of static rectangular bodies. When I move the object along the boundaries, on collision, it jitters. This is because the boundary wall pushes the body outwards while the touch pushes it against the wall. I am using linear velocity to move the body using touch. I tried to avoid this by setting the linear velocity of the body to 0 on collision with the boundary wall but it didn't work. I am trying to have a smooth movement along the boundary walls with no jitters. How can I solve this? Following snippet moves the body on touch. Linear velocity vector has direction towards the touch point. The movement is smooth within the play area but not at the boundaries. case TouchEvent.ACTION MOVE strikerBody.setLinearVelocity((pSceneTouchEvent.getX() body.getPosition().x PIXEL TO METER RATIO DEFAULT),(pSceneTouchEvent.getY() body.getPosition().y PIXEL TO METER RATIO DEFAULT)) These are the bounadry walls final Rectangle groundLeft new Rectangle(camera.getWidth() 2 camera.getWidth() 4, 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle groundRight new Rectangle(camera.getWidth() 2 camera.getWidth() 4, 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle roofLeft new Rectangle(camera.getWidth() 2 camera.getWidth() 4, camera.getHeight() 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle roofRight new Rectangle(camera.getWidth() 2 camera.getWidth() 4, camera.getHeight() 1, camera.getWidth() 2, 20, this.resourcesManager.vbom) final Rectangle leftTop new Rectangle(1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16 , 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final Rectangle leftBottom new Rectangle(1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16, 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final Rectangle rightTop new Rectangle(camera.getWidth() 1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16, 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final Rectangle rightBottom new Rectangle(camera.getWidth() 1, camera.getHeight() 2 camera.getHeight() 4 camera.getHeight() 12 camera.getHeight() 16, 20, camera.getHeight() 2 camera.getHeight() 12, this.resourcesManager.vbom) final FixtureDef wallFixtureDef PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f) PhysicsFactory.createBoxBody(this.mPhysicsWorld, groundLeft, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, groundRight, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, roofLeft, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, roofRight, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, leftTop, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, leftBottom, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, rightTop, BodyType.StaticBody, wallFixtureDef).setUserData("wall") PhysicsFactory.createBoxBody(this.mPhysicsWorld, rightBottom, BodyType.StaticBody, wallFixtureDef).setUserData("wall") this.attachChild(groundLeft) this.attachChild(groundRight) this.attachChild(roofLeft) this.attachChild(roofRight) this.attachChild(leftTop) this.attachChild(leftBottom) this.attachChild(rightTop) this.attachChild(rightBottom) |
22 | Change the shape of body dynamically I have a problem where i have a ballon which i need to continuously inflate and defalte in update method, I have tried to used setScaleCenter but it is not giving desired result. Below is a code i am trying to make work scale (float) ((dist lastDist) lastDist) Log.d("pinch","scale is " scale) Log.d("pinch","change in scale is " (float) ((lastDist dist) lastDist)) player.setScaleCenter(scale, scale) player.setScale(scale) |
22 | What to use as a Box2D renderer in a release version? I'm creating a game with libgdx. For testing physics I use a Box2DDebugRenderer, which is not fast. When I want to release my full game, what should I use as a renderer? |
22 | Why might a body suddenly stop while moving on continue platform? I have a 32x32 sprite and I make some to be platform like this for (int i 0 i lt 15 i ) attachChild(new Ground(32 i, 200, regPlatform, vertexBufferObjectManager, physicsWorld)) And I have another sprite (32x32 also) moving over those platforms (A player object) attachChild(new Player(10, 10, regPlayer, vertexBufferObjectManager, physicsWorld)) And the physicsWorld connects the player like this (Where move 1 when user click right button, and move 2 when user click left button) physicsWorld.registerPhysicsConnector(new PhysicsConnector(this, body, true, false) if (move 1) body.setLinearVelocity(new Vector2(8, body.getLinearVelocity().y)) else if (move 2) body.setLinearVelocity(new Vector2( 8, body.getLinearVelocity().y)) The Player moves smoothly form left to right and reverse. But sometimes, it is blocked. If the player move back a bit, and back again where it is blocked, it isn't blocked any more at the same place. Anyone has any idea to fix this? Maybe it is a bug of andengine and box2d and I need some trick here? Please help me. (The two sprites above are just normal png with 32x32px) Player image Platform image |
22 | Include Box2D libraries to a cocos2d project (iOS) I have a problem including box2D to my cocos2d project. I've tried different ways to do it with no success. This is what I've done I downloaded Box2D (Box2D v2.2.1) to my project directory. Dragged the Box2D directory (which includes Box2D.h, Collision, Common, Dynamics, Rope) to my Xcode project (from Finder to Xcode) Then I added include "Box2D.h" to my .h file and got many errors... Here is where I started my research P I went to Project Settings and edited the attribute Header Search Paths (contained in the Search Paths section) specifying the path of Box2D. At this point, I builded the project and I got less errors. After that, I renamed my .m file to .mm (I think this is because Box2D is written in C and with this, the compiler can treat it as it is). Still got errors. Then I tried changing the attribute Always Search User Paths (contained in Project Settings Search Paths) from YES to NO. Still got errors. As my last option I tried changing the attribute Compile Sources As (contained in Project Settings LLVM GCC 4.2 Language) from According to File Type to Objective C . By now I'm frustrated xD. I have 203 errors and most of them are in the .h files contained in the Box2d engine. b2Timer.h Expected ' ', ',', ' ', 'asm' or 'attribute' before 'b2Timer' b2Distance.h Expected specifier qualifier list before 'b2DistanceProxy' b2Math.h Cfloat No such file or directory And so on... Thanks!!! |
22 | Box2D recommended step, velocity and position iterations Here in this article there is a nice explanation that velocity iterations and position iterations settings affect the way bodies will react when they collide, and step affects on speed and how gravity acts. So the precision is hidden behind position and velocity iterations, whereas you need to have the world step to advance the time in physics world. I also know that step should be constant to be able to have consistent and debug able game physics. Hence I do this (where dt is FPS delta time) if (m world.GetBodyCount() gt 0) static const double step 1.0 70.0 static double accumulator 0.0 max frame time to avoid spiral of death if ( dt gt 0.25 ) dt 0.25 accumulator dt while (accumulator gt step) m world.Step(step, VELOCITY ITERATIONS, POSITION ITERATIONS) accumulator step So I guess the step should not be less then FPS minimum value to avoid discrete simulation (cutting effects). Usually FPS is 1 60.0 hence I have chosen 1 70 as a step to have the best performance. And as Velocity and Position iterations I use 6 and 2 respectively which turned to be enough for collisions till today. Is my logic correct or I miss something? Is there a way to optimize more? What are the recommended values for this parameters for mobile games (considering that the game should work on week devices too). Should I use non constant velocity iterations and position iterations reducing them when FPS drops? |
22 | Stopping on a slope in Box2d I am creating a simple platformer using Box2d. I've implemented a variant of the technique described here. To make the player character move more 'platformer like' I want him to stop on (shallow) slopes. However, the engine I am using does not support angle joints, so I have trouble restricting the movement of the wheel. I've tried some different alternatives that not worked Setting the horizontal velocity to 0 every game loop doesn't seem to work, because between calls the wheel catches up speed once again. Is there another way to fix this? |
22 | Box2d contant speed before and after collision I want to make my body fly at constant speed, how to make it fly at constant speed before and after collision? I set restitution of my body to 1.0 but after some direct and powerful collisions my objects begins to slow, I want it to fly same speed as before. I heard this can be done by setting liner damping of the object, I think it can prevent only from fast flying objects not slow. Thanks in advance. Edit I can simply modify velocity of the object every frame, is it a solution? var velocity b2Vec2 b.GetLinearVelocity() var speed Number velocity.Length() var ratio Number circleSpeed speed velocity.Multiply(ratio) b.SetLinearVelocity(velocity) |
22 | What is the Box2D coordinates system? I know that for Box2d I need to translate pixels to meters which is easy peasy. However my problem is what is the orientation of Box2D coordinates system? Is this the same as screen one (right x, bottom y) or it is like cartesian (right x, bottom y) ? Also, does Box2D coordination system use negative values? Thank you. |
22 | Is it bad practice to set the velocity of an object every loop? Say I have a simple game with a gameLoop function that gets called every 50 milliseconds or something similar, and I have a box2d object. Is it bad practice too CPU intensive to use SetLinearVelocity on the object every time the gameLoop is called? |
22 | Libgdx body passing through block then fall on it I'm using libgdx and its physic engine Box2d. My question is how could I make my box2d body go through a block , ignore the first collison than make the block active so the ball can fall onto it. A good example is doodle jump. |
22 | Speed seems random with constant impulse I'm shooting an object from the top vertex of a triangle using Box2dWeb. The issue I'm having is that the projectile speed seems to be fairly random, even with applyimpulse set to a constant. The gravity is set to zero. I thought it could be the physics step, changing these settings hasn't made a difference. The projectile will shoot out at very very fast speeds, then it will shoot out at its defined speed. bodyman 0 .GetBody().ApplyForce( bodyman 0 .GetBody().GetWorldVector(new b2Vec2(0, 50)), bodyman 0 .GetBody().GetWorldCenter()) |
22 | Worth using Box2d for collision but not physics? I am currently doing some work in cocos2d x and am thinking about using their box2d implementation for things like collision detection (but not necessarily response), range detection, and other things like that, which are not strictly physics based. Is it worth doing this? or would I be better off just writing a simple system that does checks based on location size of my objects? |
22 | How do the Box2d and Bullet physics simulations work internally? I've seen box2d and bullet ported into JavaScript, but neither of them attracted me, except for the source code. It all seemed quite simple, once I looked inside. What are they doing within each of those libraries to get nice physics simulation? I can not find any explanation. |
22 | In Box2D, how do I create an infinitely oscillating spring? How do I create an ideal spring that can oscillate indefinitely using Box2D? A b2DistanceJoint works almost perfectly, but it eventually slows to a stop, even with damping set to 0. I think it is because b2DistanceJoint is not meant for creating springs, but for preserving the distance between two bodies by correction the violated distance with a spring like behaviour. Hence, it should have a damping to eventually bring back the bodies to initial state and stop at some point. |
22 | Can i add friction in air? I have issue regarding speed in air. When i jump and move simultaneously that time speed of player increase.For jump i am using impuls and for movement i am using force.I want to slow speed when player is in air. Thanks in advance Following is my update method ih HUDLayer (void)update (ccTime)dt (b2Body )ballBody (CCSprite )player1 (b2World )world if (moveRight.active YES) ballBody gt SetActive(true) b2Vec2 locationworld b2Vec2(maxSpeed,0) double mass ballBody gt GetMass() ballBody gt ApplyForce(mass locationworld, ballBody gt GetWorldCenter()) ballBody gt SetLinearDamping(1.2f) else if(moveLeft.active YES) ballBody gt SetActive(true) b2Vec2 locationworld b2Vec2( 10,0) double mass ballBody gt GetMass() ballBody gt ApplyForce(mass locationworld, ballBody gt GetWorldCenter()) ballBody gt SetLinearDamping(1.2f) Following is jump (void)jump (b2Body )ballBody (ccTime)dt (BOOL)touch if (touch) if (jumpSprte.active YES) ballBody gt SetActive(true) b2Vec2 locationWorld locationWorld b2Vec2(0.0f,98.0f) locationWorld b2Vec2(0,32) double mass ballBody gt GetMass() ballBody gt ApplyLinearImpulse(locationWorld, ballBody gt GetWorldCenter()) ballBody gt ApplyForce(mass locationWorld, ballBody gt GetWorldCenter()) ballBody gt SetLinearDamping(1.2f) So where i apply logic?? |
22 | Rotate Box Sprite With Circle Body I want to rotate my rectangular sprite with circle body. The problem is the body doest not attached to the centre of the sprite. This was the default behaviour of the body and sprite. But I want that circle body attached in the bottom of the rectangle and when rotation happen at that time rectangular sprite always attached with the body at the bottom and during simulation it change its angle and position according to this only. I try to write question in words if I don't able to understand you then know me then I post a picture of my problem here. Although I know that cocos2d has setAnchorPoint method available so similar task become easily but what about my engine that right now I was using AndEngine. So be relevant to this game platform. Also thanks in advance for efforts you take. |
22 | Set Position of multiple bodies I have a character composed of five bodies which are tied together by a lot of joints. On of them is the overall chassis, to which all forces and impulses are applied to move the whole Character. All in all that works very fine, except one thing I need to set the Position of the Character so that it get Beamed from one place to the other in one single frame. Unfortunately I cannot get this to work. I tried the following code, without any success playerbodies.forEach(function (bd) bd.SetLinearVelocity(new b2.Vec2()) var t bd.GetTransform() t.p.x 10 bd.SetTransform(t, bd.GetAngle()) ) How can I make that happen? |
22 | Programmatically set color of Box2D body's sprite or image In my basic Cocos2D Box2D iPhone app I have a bunch of circular Box2D bodies. I'd like to change the color of the circles programatically. What's the easiest way to do this? So far I'm just assigning a CCSprite to the b2body userData. So perhaps I can change the colors in my sprite sheet programmatically? Seems like there's an easier way. I'm just not sure what it is. Cheers! |
22 | Box2D strange collisions (jitter) on sharp edges I'm currently developing 2D side scroll game with Libgdx Box2D. And I'm facing some problems with ChainShape (the ground) and PolygonShape (the cart body) collisions. Please look at this video http www.youtube.com watch?v gljgMn8lYfs As you see the PolygonShape jitters(?) when collides with ChainShape. BUT it only happens on sharp edges! What I've tried Increase decrease velocityIterations positionIterations. Didin't help. Currently they are set to 10 8 (as shown in video). Turn off CCD. Didin't help. Currently is turned on. Set velocityThreshold to zero. Didin't help. Currently is default 1f. Set restitution friction values to zero. Didin't help. Any suggestions why it's happening and how can I fix avoid it? |
22 | How to set a body to a specific position using Andengine I'm developing a game with a single player and multiplayer mode. Lets say I have walls (static bodies), vehicles (dynamic bodies) and bullets (dynamic bodies). It works fine to control my own vehicle using vehicleBody.setLinearVelocity(velocityX, velocityY) . The vehicle can collide with walls and bullets as expected. Now I like to move the enemy vehicles in multiplayer mode. When I use the same method to move the body by its velocity values (in multiplayer mode), the vehicles get out of sync really quickly, means they don't have the same position on all devices because some data packages get lost. What I'm currently doing is the following On device 1 1) I move the body using setLinearVelocity 2) Then I get the X and Y position of the body and send a data package to the other device On device 2 3) I receive the data package and set the position of the body. I tried different ways, hopefully you can tell me the best way or alternatives I did not try yet using vehicleBody.setTransform(...) activity.runOnUpdateThread(new Runnable() Override public void run() vehicleBody.setTransform(new Vector2(newPosX, newPosY), angle) ) I also tried using MouseJoint (based on that tutorial), but somehow the body was bouncing randomly to the next position. Sometimes it was working great, but when I restarted the game the vehicle of the enemy started bouncing again. Maybe I failed to setup the parameters. Here is what I used public MouseJoint createMouseJoint(float newPosX, float newPosY) final float PIXEL TO METER RATIO PhysicsConstants.PIXEL TO METER RATIO DEFAULT Vector2 v vehicleBody.getWorldPoint( new Vector2(newPosX PIXEL TO METER RATIO, newPosY PIXEL TO METER RATIO)) MouseJointDef mjd new MouseJointDef() mjd.bodyA groundBody mjd.bodyB vehicleBody mjd.dampingRatio 0.2f mjd.frequencyHz 30 mjd.maxForce (float) (1000.0f vehicleBody.getMass()) mjd.collideConnected true mjd.target.set(v) return (MouseJoint) mScene.mPhysicsWorld.createJoint(mjd) Before I've used bodies I was using simple sprites and it worked perfectly. I sent data packages to the other device(s) and set the position and rotation of the enemy vehicle by using vehicleSprite.setX(newPosX), vehicleSprite.setY(newPosY) and vehicleSprite.setRotation(angle). Compared to that, bodies seem to be very complicated. So how I can I keep positions synced without bouncing? By the way, on some pages I read about using KinematicBody instead of DynamicBody for a vehicle. What is the advantage? My vehicle needs to collide with the environment, so I think DynamicBody is the correct choice, isn't it? |
22 | Farseer Friend Foe Collision cannot push foes but friends we are using Farseer in our project and I try to find a setup to achieve the following quite complicated collision behavior Friendly Units can push each other aside. However, the push should be a "soft push", so that multiple units can squeeze through narrow gaps. Enemy Units should not be pushed. Ever. Moving units colliding with enemies should stop dead. Additionally, I have some other type of collider, lets call them "Wall" ). Neither friends nor foes should ever be able to stand inside a wall. Whether two objects are considered "enemies" can change dynamically during the game. The state is always symmetric (If Bob is an enemy of Alan, then Alan is always an enemy of Bob) but we have more than two factions (up to 16). (Basically, its a similar collision behavior like Starcraft, except that friendly units can temporarily squeeze through navmesh gaps.. much like in Age of Empire..) Actually, I got a quite elaborated solution so far. It has some problems, but kind of gets most of my wishlist done.. Well, most of the time. Here is what I did.. Lets first start with the setup without any walls (because that's what is working better ) I have 2 bodies for each unit. One dynamic the other kinematic. the dynamic body has two equal fixtures. One sensor (to soft push friends), the other a normal fixture (this is what I apply forces from outside game code). The kinematic body has one normal fixture. (This body is to dead stop on enemies) I hooked a BeforeCollision callback to the normal fixture of the dynamic sensor. This filters out all collisions except with the kinematic body of enemies. This way, the dynamic body can not push enemies. Another BeforeCollision filter on the kinematic body just excludes collisions with the sensor fixture of our own dynamic body. Now, after every world update, I run through all the dynamic bodies I will copy the new position into the kinematic body. For each touching contact of the sensor with another dynamic body, I will manually calculate a separating force and apply these to both dynamic bodies. Everything clear so far? To summarize Dynamic fixture moved by game code, stops dead colliding with kinematic body of enemies. Sensor register friends and I calculate push forces by hand. Kinematic body is synched every frame to the dynamic body. Now the problem Walls. I need to enforce that no Body ever ends up inside a wall. More precise, the center point of any body must not be inside any Wall shape (the circle can and should overlap with the wall, only the center point is interesting). I tried several ideas to achieve this but running out of steam here. The currently best solution I could come up with The dynamic body gets yet another circle fixture that is extremely small, like 0.001 meter. This one has a CCD on and a collision group that only allows collision with walls (which are in their own category) Walls are all fixtures of a static body. This approach works as long as no "teleporting" of units is involved. Lets say Alan is being teleported on a spot overlapping with Bob. Now, Alan's kinematic body will push Bob's dynamic body and vice versa. Everything is fine. But if Bob was standing right next to a wall, Farseer will still move Bob slightly into the wall, since the resolver need to resolve the unmovable kinematic body of Alan and the unmovable wall. Yet another post update loop through all bodies that scans all units whether they are inside walls and manually resolve their positions is way beyond our performance limits. I briefly thought about some solution involving two separate Farseer worlds, but my head starts to spin trying to figure out which body position need to be copied where and when... I haven't looked into joints yet, but my gut feeling is that they don't really help here. Except with a third body? Do I really need 3 bodies per unit? ( Any ideas? |
22 | Explain the difference between extrapolation and interpolation http www.unagames.com blog daniele 2010 06 fixed time step implementation box2d here there are two algorithms of smoothing in case of fixed time step physics simulation. I don't understand the formula of interpolation state currentState alpha previousState (1 alpha) And also I don't understand the comparison figure. Please explaing what is the meaning of multiplying current state with alpha and summing with previous state with 1 alpha. |
22 | Rotating an object about a point (2D) using box2d i just started developing using box2d on flixel and i realise the pivot point of the rotation of an object in box2d is set to the center of an object. i had read on forums and i found out that SetAsBox can change the pivot point of the object, however, i cannot seem to get it work to rotate about a point. what i would like to achieve is to rotate an object about a point like earth revolving around the sun. any one can help me with it? really thanks a lot and sorry for the bad english |
22 | Making the player walk on walls in box2d I'm making a game in stencil where players walk form left to right along randomly generated walls. I cant use waypoints, since the walls' shapes and positions are unpredictable. Here's a descriptive sketch The red line is the player's path. The red circles are what I thought might make good waypoints until I scrapped the idea. |
22 | Box2d How to connect distance joint to the ground? I have a rectangular fixed size world. I want to connect a body inside it to any place(near that body) in the world with a b2DistanceJoint. Do I need to create a large static body with the size of the world that can't collide with anything? Or is there a better method? Will it slow down simulation speed if I have around 300 bodies moving on the surface of this static body? |
22 | What scaling system to use in Box2d? I'm worried about this Caution box from the Box2d manual Box2D is tuned for MKS units. Keep the size of moving objects roughly between 0.1 and 10 meters. You'll need to use some scaling system when you render your environment and actors. The Box2D testbed does this by using an OpenGL viewport transform. DO NOT USE PIXELS. I don't want to use OpenGL since I know nothing about it. I'm using SFML to render my game. |
22 | Client side physics simulation I am trying to create a very simple client server based physics game, using box2d library. A simple football game. Obviously, the server runs only the box2d world. My question is is it correct to state that the client should run not only the needed rendered simulation but another box2d world as well? I ask this because I know that the client should receive state information of the elements that have a changing state. And this information is received in packets every few ticks. And between every packet received, there's a time gap where I need to run the world like "nobody did nothing", and then correct the world state if somebody did something after I received the next packet. That is why I need to run the box2d world in the client as well, but I feel it's kinda awkward and assymetrical. Is this right? Is box2d prepared for this? |
22 | How to make an object in box2d have constant velocity even after collision? I have iOS game where I have a bouncing character. Everything is being handled by box2d. The problem is when the character hits a wall of another character it's velocity changes, but I don't want this. I need the velocity to stay constant even after collisions. I was thinking the only way to do this was to keep setting the velocity after each collision unless there's another way to do this that I'm not aware of? |
22 | Dynamic body in Box2D with fixed position I need to fix the dynamic body position so that it would not rotate and would not move even if there are other forces, collisions and so on. Let me first explain why I need this. I have a dynamic body which is the game character. There are non moving objects that the game character should land on and get some energy as long the character is in contact with those bodies. As these bodies are non moving it would be natural to make them Static or Kinematic. But in my case I cannot do that, as far as there is another Kinematic body with which all the game items should be collided and on EndCollision event those items should be removed. But in Box2D static and kinematic bodies don't collided with each other. So I have to make my game item on which the character should land Dynamic but still should be sure that it will not move. How should I do this? |
22 | Sizing a Box2D ground object I am developing a platformer game using SDL2 for graphics and Box2D for physics. I am currently designing my levels and would like to know if it is better to make the static part of each level (ie ground) one big (500 units wide) polygon or to break each level up into multiple tiles just a few units wide. The Box2D manual says that I should keep my objects small to avoid bugs in the floating point code but having a single large ground object seems like a resonable way of reducing the number of objects in the simulation. So, can I make my ground object one large 500 unit polygon or should I break it up into many smaller 1 2 unit polygons. |
22 | Is it possible to apply a texture inside a GL LINE LOOP? I am creating a game using Box2D and OpenGL ES 1.1. I am taking the b2PolygonShape vertices and converting them into an OpenGL ES 1.1 GL LINE LOOP. The debugging view looks great, but now I want to apply textures to the inside of the line loop. Is this possible? I used line loop instead of triangles because I am not sure how to handle complex polygons using triangles. |
22 | Is it possible to apply a texture inside a GL LINE LOOP? I am creating a game using Box2D and OpenGL ES 1.1. I am taking the b2PolygonShape vertices and converting them into an OpenGL ES 1.1 GL LINE LOOP. The debugging view looks great, but now I want to apply textures to the inside of the line loop. Is this possible? I used line loop instead of triangles because I am not sure how to handle complex polygons using triangles. |
22 | Moving player in Box2d without forces How do I move player with keyboard without applying forces? If I do playerBody.setLinearVelocity(new B2Vec2(0, 2)) it moves the player but when I release the key for movement, the ball is continuously moving for few seconds. |
22 | changing body type without change of center of mass I have an box2d project with some bodies in it, which move around without any user interaction. But if the user selects one of the bodies, he should be able to move it around just like he wants to. To keep it short, I want to change the type of the body to "kinematic" while the user controls it and back to "dynamic" afterwards. If I do so the rotation center of the body changes with the change of the type. How can I reset this? The body's fixture is created of a single b2PolygonShape, with its vertices set via SetAsArray(). Greetings philipp EDIT So I looked around about setting the local center of bodies. what brought me to this solution var md new b2MassData() this.body.GetMassData( md ) this.body.SetType( b2body.b2 kinematicBody ) this.body.SetMassData( md ) that did not work, so I had a look at the source and found that SetMassData() always returns if the body is not "dynamic". So I tried this var md new b2MassData() this. body.GetMassData( md ) this. body.SetType( b2Body.b2 kinematicBody ) this. body.m sweep.localCenter.Set( md.center.x, md.center.y ) what actually is modifying the private data of the body. But it works and no errors appear, but can I really do this without the risk of breaking the application, or in other words, under which circumstances could this solution might cause errors? n.b. I am using box2dweb of the latest release. Greetings philipp |
22 | web based networked game physics efficiency I am writing a web based game, using websockets. its pretty simple, two players shooting at each other with bullets that have acceleration from a starting point at an angle. The client side (frontend in web dev terms) uses phaser.io with p2js for physics. However after reading this post, i believe that it's smarter to do some of the physics for the players on the server side. Such as collision detections, and update the player positions at regular intervals to keep the two players at sync. Now i have two questions if i use the Box2d javascript port on nodejs on the server side to simulate server side physics, than is it just as efficient as using the native c one? seeing as from what i have read so far it seems the js ports aren't that well maintained, and they are js ported on the other hand the js codes might be easier to deal with than the c ones. using p2js on the client side and using box2d on the server. The server being authoritative, and sends regular updates (once every second) as to the actual positions of the players. will the physics simulation be in sync (atleast to the user)? Theoretically i don't see any reason for it to not, given that both user has the exact same latency (this is assumed for sake of simplicity). |
22 | Include Box2D libraries to a cocos2d project (iOS) I have a problem including box2D to my cocos2d project. I've tried different ways to do it with no success. This is what I've done I downloaded Box2D (Box2D v2.2.1) to my project directory. Dragged the Box2D directory (which includes Box2D.h, Collision, Common, Dynamics, Rope) to my Xcode project (from Finder to Xcode) Then I added include "Box2D.h" to my .h file and got many errors... Here is where I started my research P I went to Project Settings and edited the attribute Header Search Paths (contained in the Search Paths section) specifying the path of Box2D. At this point, I builded the project and I got less errors. After that, I renamed my .m file to .mm (I think this is because Box2D is written in C and with this, the compiler can treat it as it is). Still got errors. Then I tried changing the attribute Always Search User Paths (contained in Project Settings Search Paths) from YES to NO. Still got errors. As my last option I tried changing the attribute Compile Sources As (contained in Project Settings LLVM GCC 4.2 Language) from According to File Type to Objective C . By now I'm frustrated xD. I have 203 errors and most of them are in the .h files contained in the Box2d engine. b2Timer.h Expected ' ', ',', ' ', 'asm' or 'attribute' before 'b2Timer' b2Distance.h Expected specifier qualifier list before 'b2DistanceProxy' b2Math.h Cfloat No such file or directory And so on... Thanks!!! |
22 | Error in destroying object in Box2D LibGDX I'm trying to delete an object when a collision happens. I have put the following code in the render method of the object so it would be outside of the physics calculations. public void render(SpriteBatch spriteBatch) some other code... body.setActive(false) body.getWorld().destroyBody(body) But I'm getting an run time error which crashes the JVM and shows, AL lib alc cleanup 1 device not closed Assertion failed! Program C Program Files Java jre6 bin javaw.exe File var lib hudson jobs libgdx git workspace gdx jni Box2D Dynamics b2World.cpp, Line 133 Expression m bodyCount 0 Can anyone help me here? |
22 | box2d resize bodies arround point I have a compound object, consisting of a b2Body, vector graphics and a list polygons which describe the b2body's shapes. This object has its own transformation matrix to centralize the storage of transformations. So far everything is working quiet fine, even scaling works, but not if i scale around a point. In the initialization phase of the object it is scaled around a point. This happens in this order transform the main matrix transform the vector graphics and the polygons recreate the b2Body After this function ran, the shapes and all the graphics are exactly where they should be, BUT after the first steps of the b2World the graphical stuff moves away from the body. When I ran the debugger I found out that the position of the body is 0 0 the red dot shows the center of scaling. the first image shows the basic setup and the second the final position of the graphics. This distance stays constant for the rest of the simulation. If I set the position via myBody.SetPosition( sx, sy ) the whole scenario just plays a bit more distant for the origin. Any Idea how to fix this? EDIT I came deeper down to the problem and it lies in the fact that i must not scale the transform matrix for the b2body shapes around the center, but set the b2body's position back to the point after scaling. But how can I calculate that point? EDIT 2 I came ever deeper down to it, even solved it, but this is a slow solution and i hope that there is somebody who understands what formula I need. assuming to have a set polygons relative to an origin as basis shapes for a b2body scaling the whole object around a certain point is done in the following steps i scale everything around the center except the polygons i create a clone of the polygons matrix i scale this clone around the point i calculate dx, dy as difference of clone.tx original.tx and clone.ty original.ty i scale the original polygon matrix NOT around the point i recreate the body i create the fixture i set the position of the body to dx and dy done! So what i an interested in is a formula for dx and dy without cloning matrices, scaling the clone around a point, getting dx and dy and finally scale the vertex matrix. |
22 | Calculate the rest length of a box2d distance joint Given the length of a distance joint along with its frequency and the mass of the bodies involved, is it possible to determine the final rest length? I'm only interested in the vertical axis if that makes the formula simpler. E.g. Imagine the simple case of a dynamic body of mass 1 sitting vertically atop another similar body and attached via a distance joint with length 1 and frequency 1 and gravity 10. What would the rest length be? I.e. What would the final distance be between those two bodies? I'm currently just trial and error fudging the frequency values I need in my game but I really need a formula to compute this as every time I change the masses, I have to re fudge everything. Thanks. |
22 | Handling player background movements in 2D games Suppose you have your animated character controlled by the player and a 2D world (like the old 2D side scrolling games). When the user presses right on the keyboard, the background is moved to the right. If the path is always horizontal, this is simple to do (incrementation decrementation of the x coordinate). But suppose that the path is instead a polygonal chain. My questions are How do you move the background? How do you move the background if the game objects are managed with a physics engine like box2D? Note. What I wanted to ask is, how do you move a 2D character in a side scroller? For example, consider the following path A B C' D' C D You start from A, move horizontally to B, then move diagonally to C, then move horizontally to D OR, from B, jump on C' and continue till D' and so on. |
22 | box2d prismatic joint friction I know it is possible to add friction to rev joints by enabling motor and adding maxMotorTorque. I want the same for prism joint but only maxMotorSpeed option is available which didn't quite work for me. Is there another way? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.