Page 1 of 1

3rd person camera shooter game in C++DirectX need guidance

PostPosted: Thu Dec 28, 2017 6:14 am
by grimreaper2017
Hi people, developing a 3rd Person shooter (under the water game) in C++ and Direct X. I've got the firing mechanism to work - perfect.

But I want to advance my own skills, I have been toying with the idea of using Homing Missile (been struggling over the idea for a few months now), any ideas on resources in C++ in this field? I can create one in Unity & Unreal (blue prints). but trying to do one in C++ is driving me nuts. Even if it is in 2D, and I can reverse engineer the code

or something it would be a start. :(

Re: 3rd person camera shooter game in C++DirectX need guidan

PostPosted: Tue Jan 02, 2018 5:53 pm
by dandymcgee
The logic would be the same as any "follow" mechanism. Essentially, just set the follower's acceleration in the direction of the target each frame.

Untested pseudocode (this is C, feel free to replace C idioms with C++ idioms, e.g. std::vector<Entity>):
const float ENTITY_ACC = 1.0f;

typedef struct vec2
float x, y;
} vec2;

typedef struct entity
vec2 pos;
vec2 vel;
vec2 acc;
entity *target;
} entity;

void update_entities(int count, entity *entities)
for (int i = 0; i < count; ++i)
if (entities[i].target != NULL)
float delta_x = entities[i].target.pos.x - entities[i].pos.x;
float delta_y = entities[i].target.pos.y - entities[i].pos.y;
entities[i].acc.x = (delta_x > 0.0f) ? ENTITY_ACC : -ENTITY_ACC;
entities[i].acc.y = (delta_y > 0.0f) ? ENTITY_ACC : -ENTITY_ACC;

// TODO: Check if entities[i].type == HOMING_MISSILE && are_colliding(entities[i], entities[i].target)
// If so, damage target, delete missile, etc.

Re: 3rd person camera shooter game in C++DirectX need guidan

PostPosted: Wed Jan 03, 2018 8:28 pm
by dandymcgee
Also, while this is not directly related to your question, I just found this great resource for 2D games that you might like to read: