## How should bullet reflections be implemented?

Im working on a tank game where bullets are relected off of walls. The formula for a relfection is r=d−2d⋅n∥n∥2n where d is the incoming vector and n is the normal of a wall. My bullets stick to the walls and then "bounce" off at the corners; an undesirable effect. Im honestly questioning my formula implementation at this point.

``````func collision():
for i in get_slide_count():
var collision = get_slide_collision(i)
if collision.collider.is_in_group(globals.wall_group):
var normal = collision.normal
velocity = velocity - ((2 * velocity.dot(normal)) / normal.length_squared()) * normal
rotation = velocity.angle() + PI
``````

if i use the is_on_wall function and simply negate the velocity this does produce a bouncing effect but not a correct one. I still need the normal.
I orignally used rigid bodies as seen in the image. But i have switched to kinematic bodies.

## android – How to build bullet (hit) damage detection in Augmented Reality to a real life person acting as an opponent?

I am building an Android AR game using ARcore 1.18 in Unity 2019.4.5f1 (LTS). Now I want to create something like bullet damage detection just like it is built in a normal Unity 3D game.

Of course, the biggest problem is how can I even detect the real person’s hitbox like it is done in a normal game? I need to somehow be able to attach the bullet damage script to the body of the real-life person in real-time.

Has anyone tried this before? How can we achieve this? I understand if I might not get a spoonfed tutorial but some help towards what should I be doing to achieve this will be greatly appreciated.

I see some other FPS Augmented Reality games which either uses Laser Tag (Father.io) or Barcodes to scan the opponents. These are definitely some great ideas to create an FPS game experience but still, if possible, I want to try it with just the mobile camera without any external support. I am ready to bear some accuracy loss 🙂

## libgdx – Bullet: Mesh drops after debug lines turn green

My mesh drops after a while when rigid body turns green. Maybe I sound wierd, but I am new to bullet-physics and 3d stuff, and don’t know the actual cause ;P

It happens on using MotionState.
Initial state:

After debugdraw turn green

Here is my code inside render method:

``````        delta = Math.min(1f / 30f, Gdx.graphics.getDeltaTime());

world.stepSimulation(delta, 5, 1f/60f);
stickobj.body.getMotionState().getWorldTransform(stickobj.transform);
modelBatch.begin(cam);
modelBatch.render(stickobj, environment);
modelBatch.end();
``````

Here is my motion State for stickman:

``````class StickMotionState extends btMotionState {

Matrix4 transform;

StickMotionState(float r){
}

@Override
public void getWorldTransform(Matrix4 trans) {
trans.set(transform);
}
@Override
public void setWorldTransform(Matrix4 trans) {
transform.set(trans);
}
}
``````

It works fine without explicitly calling,
`stickobj.body.getMotionState().getWorldTransform(stickobj.transform);` as Xoppa stated in this tutorial, but then my model is offset a little bit.

Also, I don’t want to offset origin in blender due to increased calulations in placing them in game.
PS: What does that green colour signifies 😛

## libgdx – Bullet Physics has a 45 degree axis shift. How do I adjust the offset?

I am using Libgdx and Physics Bullet to make a simple 3D Android game. When I apply central force to the rigid body in the z direction, that is `Vector3 (0.0,0.0,-5.0)`, the rigid body really diagonally rather than straight. The angle is around 45 degrees.

How do I adjust the offset? Are there any settings I can configure to eliminate this offset?

Any reading material on this would be great.

## c ++ – How to generate random waves for a game of bullet hell that feels balanced and natural

My game consists of & # 39; waves & # 39; of objects called & # 39; players & # 39 ;, that once in a while (their fire time), move to a new place on the screen and generate an enemy. Each wave has 4 important properties:
1: the number of players the wave has
2: the time interval between creating new players
3: the total wave length
4: the types of players that can appear in a wave (represented as a `std::vector>` where the string is the name of the generator and the whole number is its generation weight.

The game works by selecting a random generator of the possible types of players (with a weighted rng) each new range of players. Currently the waves are established and loaded from a file at runtime.

My problem is that I can't find a good way to generate random waves that feel balanced and natural. Currently, I am trying to generate waves based on a difficulty value, mainly using the generation of weighted random numbers. However, this does not produce balanced waves that correspond well with the target difficulty. Even after trying several different techniques, I cannot obtain a system that generates balanced and natural waves (such as those made by hand).

Is there any way to generate waves that feel natural, based on the value of difficulty? How should I address this problem?

In addition, if it is of any help, each generator also defines its own difficulty value.

## Postprocessing: how do I create a bullet in Photoshop Elements 11?

In Expert mode:

1) Choose the Elliptical frame tool and draw an oval or circle on the image.

Adjust the shape using Select> Transform Selection and using the handles in the transformation box to alter the size, adjust the shape or move it. When you have finished adjusting, click on the green check mark accept the selection

2) Go to the Select menu and choose Reverse: to allow you to work with the area outside its shape (instead of the area within it).

3) Smooth the edge of the selection so that the line becomes less obvious, use the Feather slider to blur the edge. Click OK Once you're happy with the result.

4) Color the vignette using Edit menu> Fill selection. Several presets are offered, including Black / Gray / White, otherwise choose from the color picker.

5) Make a selection of Normal drop-down menu option, or adjust the opacity of the chosen color fill.

NOTE: returning to the Fill selection and reducing the opacity selected does not lighten the existing choice. Instead add the new opacity in the existing fill, making the color of the fill thicker. If you want to change to a lower opacity, first undo the fill selection, then make the fill and opacity completely again.

6) Click OK to accept the current configuration.

DONE. Save your new image as you normally would.

## c ++ – A basic example cannot be obtained by working with Bullet 3 (haxebullet port)

Example of my code:

``````var collisionConfiguration = new bullet.Bt.DefaultCollisionConfiguration();
var dispatcher = new bullet.Bt.CollisionDispatcher(collisionConfiguration);
var solver = new bullet.Bt.SequentialImpulseConstraintSolver();
var dynamicsWorld = new bullet.Bt.DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

var groundShape = new bullet.Bt.StaticPlaneShape(new bullet.Bt.Vector3(0, 1, 0), 1);
var groundTransform = new bullet.Bt.Transform();
groundTransform.setIdentity();
groundTransform.setOrigin(new bullet.Bt.Vector3(0, -1, 0));
var centerOfMassOffsetTransform = new bullet.Bt.Transform();
centerOfMassOffsetTransform.setIdentity();
var groundMotionState = new bullet.Bt.DefaultMotionState(groundTransform, centerOfMassOffsetTransform);

var groundRigidBodyCI = new bullet.Bt.RigidBodyConstructionInfo(0.01, groundMotionState, cast groundShape, new bullet.Bt.Vector3(0, 0, 0));
var groundRigidBody = new bullet.Bt.RigidBody(groundRigidBodyCI);

var fallShape = new bullet.Bt.SphereShape(1);
var fallTransform = new bullet.Bt.Transform();
fallTransform.setIdentity();
fallTransform.setOrigin(new bullet.Bt.Vector3(0, 50, 0));
var centerOfMassOffsetFallTransform = new bullet.Bt.Transform();
centerOfMassOffsetFallTransform.setIdentity();
var fallMotionState = new bullet.Bt.DefaultMotionState(fallTransform, centerOfMassOffsetFallTransform);

var fallInertia = new bullet.Bt.Vector3(0, 0, 0);
// fallShape.calculateLocalInertia(1, fallInertia);
var fallRigidBodyCI = new bullet.Bt.RigidBodyConstructionInfo(1, fallMotionState, fallShape, fallInertia);
var fallRigidBody = new bullet.Bt.RigidBody(fallRigidBodyCI);

for (i in 0...3000) {
dynamicsWorld.stepSimulation(1 / 60);

var trans = new bullet.Bt.Transform();
var m = fallRigidBody.getMotionState();
m.getWorldTransform(trans);
trace(trans.getOrigin().y());
trans.delete();
}
``````

It is a haxe port for Bullet3, but I think that all the components and the concept / logic remain the same as in c ++. The idea is that the `fallShape` should bounce against the `groundShape`. But it does not. When printing the `trans.getOrigin().y()` It takes you to negative numbers. So what am I doing wrong?

## c ++ – Invalid bullet physics pointer in free

I am writing a C ++ game engine with Irrlicht and Bullet Physics. All my Irrlicht code works perfectly, but when creating Bullet Physics objects with new ones and then releasing them, my program throws a `free(): invalid pointer` error.

Going back with gdb shows that the error is a libc `raise()` When the Irrlicht trees remove an Octree that I am using for the game map: `irr::scene::COctreeSceneNode::deleteTree().`

The full trace of gdb is:

``````free(): invalid pointer

0x00007ffff7455f25 in raise () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff7455f25 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff743f897 in abort () from /usr/lib/libc.so.6
#2  0x00007ffff7499258 in __libc_message () from /usr/lib/libc.so.6
#3  0x00007ffff74a077a in malloc_printerr () from /usr/lib/libc.so.6
#4  0x00007ffff74a214c in _int_free () from /usr/lib/libc.so.6
#5  0x00007ffff7bd3b69 in irr::scene::COctreeSceneNode::deleteTree() ()
from /usr/lib/libIrrlicht.so.1.8
#6  0x00007ffff7bd41ae in irr::scene::COctreeSceneNode::~COctreeSceneNode() ()
from /usr/lib/libIrrlicht.so.1.8
#7  0x00007ffff7bd4474 in virtual thunk to irr::scene::COctreeSceneNode::~COctreeSceneNode() () from /usr/lib/libIrrlicht.so.1.8
#8  0x00007ffff7bf2706 in irr::scene::CSceneManager::removeAll() ()
from /usr/lib/libIrrlicht.so.1.8
#9  0x00007ffff7bf971e in irr::scene::CSceneManager::~CSceneManager() ()
from /usr/lib/libIrrlicht.so.1.8
#10 0x00007ffff7bf9c54 in virtual thunk to irr::scene::CSceneManager::~CSceneManager() () from /usr/lib/libIrrlicht.so.1.8
#11 0x00007ffff7d45e5e in irr::CIrrDeviceLinux::~CIrrDeviceLinux() ()
from /usr/lib/libIrrlicht.so.1.8
#12 0x00007ffff7d45f54 in virtual thunk to irr::CIrrDeviceLinux::~CIrrDeviceLinux() () from /usr/lib/libIrrlicht.so.1.8
#13 0x000055555556b97e in irr::IReferenceCounted::drop() const ()
#14 0x000055555556a88f in IrrlichtHandler::drop_device() ()
``````

The code that seems to be the cause of the error is initialization:

``````    /* PHYSICS SETUP*/
btDefaultCollisionConfiguration *col_config = new btDefaultCollisionConfiguration();
btCollisionDispatcher *dispatcher = new btCollisionDispatcher(col_config);
btSequentialImpulseConstraintSolver *solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld *dynamics_world = new btDiscreteDynamicsWorld(
dispatcher, overlapping_pair_cache, solver, col_config
);

dynamics_world->setGravity(btVector3(0,-10,0));
``````

and Bullet removal:

``````irrlicht_handler.drop_device();

for(int i=dynamics_world->getNumCollisionObjects()-1; i>=0; i--)
{
btCollisionObject *obj = dynamics_world->getCollisionObjectArray()(i);
btRigidBody *rb = btRigidBody::upcast(obj);
if(rb && rb->getMotionState())
{
delete rb->getMotionState();
}
dynamics_world->removeCollisionObject(obj);
delete obj;
}

delete dynamics_world;
delete solver;
delete overlapping_pair_cache;
delete dispatcher;
delete col_config;
``````

The full code is in Github: https://github.com/morgenm/PMC-Game/tree/master/src

## c ++ – Bullet Physics Step Simulation Crash when fixedTimeStep is not 0

I am using Bullet physics together with Irrlicht. My program crashes constantly when fixedTimeStamp is not set to zero when stepSimulation is called. I think it has something to do with the time between the calls of StepSimulation because when I stopped Irrlicht from drawing the scene, Bullet worked perfectly well. Here is my stepSimulation call:

``````dynamics_world->stepSimulation(frame_delta_time, 0);
``````

The default lock does not occur when fixedTimeStamp is zero. I would like to find a better solution for this, since I have read that disabling the sub-step is experimental. Does anyone know how to fix this?

The parameters I am using when calling bullet stepSimulation () are:

``````const irr::u32 then = device->getTimer()->getTime();
...
const irr::u32 now = device->getTimer()->getTime();
const irr::f32 frame_delta_time = (irr::f32)(now-then)/1000.f;
``````

The value of frame_delta_time when the program crashes is 0.009.

The gdb stack trace indicates that the program is crashing in releasePredivtiveContacts ():

``````Program received signal SIGSEGV, Segmentation fault.

#0  0x000055555557463b in btDiscreteDynamicsWorld::releasePredictiveContacts() ()
#1  0x00005555555746fc in btDiscreteDynamicsWorld::createPredictiveContacts(double) ()
#2  0x0000555555573c8f in btDiscreteDynamicsWorld::internalSingleStepSimulation(double) ()
#3  0x0000555555575335 in btDiscreteDynamicsWorld::stepSimulation(double, int, double) ()
``````

## Japan: Tokyo bullet train to Osaka (with stops)

I am planning a trip from Tokyo to Osaka, with a stopover in Nagoya for 2 nights to travel to Takayama and continue to Osaka.
Should I do one more stopover in Kyoto or is a day trip better?
Also, can I book a single trip from Tokyo to Osaka and get on and off in Nagoya and Kyoto?