FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál

How detect collision between object1[i] and object2[j] then do something with them in Box2D games?

I am making a simple game with Box2D and SDL2. I have GameObjects vectors for example: 1.vector of Enemy 2.vector of Bullets… in ContactListener class i can detect collision between enemyFixture and bulletFixture. How i can detect contact between Enemy[i] with Bullet[j] and do something only with Enemy[i] or Bullet[j]?! Thank you for your helps.

  • ✇Recent Questions - Game Development Stack Exchange
  • Connecting bodies together in jbox2dZiv the fire
    Im trying to connect bodies together to make some sort of a "building" system or more specifically im trying to make multiple "blocks" connect to eachother but Struggling to figure out what's the best method to do it I tried using joints (created a jointDef and a joint) but I have no idea how. I can make a single large body but I want different parts of the body to have different friction values
     

Connecting bodies together in jbox2d

Im trying to connect bodies together to make some sort of a "building" system or more specifically im trying to make multiple "blocks" connect to eachother but Struggling to figure out what's the best method to do it I tried using joints (created a jointDef and a joint) but I have no idea how. I can make a single large body but I want different parts of the body to have different friction values

  • ✇Recent Questions - Game Development Stack Exchange
  • Jbox2d simulation runs slowlyZiv the fire
    I wanted to use jbox2d for my project but I have a issue the physics simulation is running very slowly I tried to change game loops and it did not run any faster the best solution I found is still like half the speed it should be game loop code (FPS = 60): double drawInterval = 1000000000/FPS; double delta = 0; long lastTime = System.nanoTime(); long currentTime; while(thread != null) { currentTime = System.nanoTime(); delta+= (currentTime-lastTime)/drawInte
     

Jbox2d simulation runs slowly

I wanted to use jbox2d for my project but I have a issue the physics simulation is running very slowly I tried to change game loops and it did not run any faster the best solution I found is still like half the speed it should be

game loop code (FPS = 60):

    double drawInterval = 1000000000/FPS;
    double delta = 0;
    long lastTime = System.nanoTime();
    long currentTime;
    while(thread != null) {
        currentTime = System.nanoTime();


        delta+= (currentTime-lastTime)/drawInterval;


        float md = (float) (delta/1000000.0);

        lastTime = currentTime;

        if(delta >= 1) {
            world.step((float)delta ,8,3);

            tick(delta);
            System.out.println("e");
            repaint();
            delta--;

        }

    }

How do make a box collider align with a line renderer continuously?

I am having the issue of aligning my BoxCollider2D with my linerenderer.

I am trying to have a laser shoot using:
Physics2D.Linecast(startingPoint.transform.position, maxEndPoint.transform.position);

This works fine and the line is always shooting in the right direction and angle when I rotate the object. But, when I am drawing a box collider, the box doesn't align at the correct position.

Firstly, the boxcollider is attached as a child component of the line renderer.

I am using this code to get the size of the collider, which seems to work fine.

float lineLength = Vector3.Distance(lazer.GetPosition(1), lazer.GetPosition(0)); 

This code is for aligning the collider with the line renderer. I know I am supposed to get the midpoint, because that's how you control the location of the box collider, but I need to know the math to always make it align.

    lazerCollider.offset = new Vector3(0, ourHitPos.y - startingPoint.transform.position.y, 0) / 2;
    lazerCollider.size = new Vector3(lazerWidth, lineLength, 0);

This is when the beam is vertical This is if the beam is rotated

I know right now I am only using the Y coordinate... I just need to know the math to make this work.

  • ✇Recent Questions - Game Development Stack Exchange
  • Wheel Joint Implementation in AndEngineSiddharth
    I am currently developing car game in AndEngine. In which I was using revolute joint for car wheel and chassis attachment. But my friend suggest me that use wheel joint for that purpose for better behavior of the car. In AndEnginen I didn't found the wheel joint implementation. So what I have to do for wheel joint implementation. I think I have to manually update the box2d library for this purpose but I don't know how many things get updated. Please suggest me some guidance on achieving better
     

Wheel Joint Implementation in AndEngine

I am currently developing car game in AndEngine. In which I was using revolute joint for car wheel and chassis attachment. But my friend suggest me that use wheel joint for that purpose for better behavior of the car. In AndEnginen I didn't found the wheel joint implementation. So what I have to do for wheel joint implementation.

I think I have to manually update the box2d library for this purpose but I don't know how many things get updated. Please suggest me some guidance on achieving better car behavior in AndEngine.

❌
❌