Page 1 of 1

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

Posted: Thu Dec 28, 2017 4: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

Posted: Tue Jan 02, 2018 3: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.target != NULL)
        {
            float delta_x = entities.target.pos.x - entities.pos.x;
            float delta_y = entities.target.pos.y - entities.pos.y;
            entities.acc.x = (delta_x > 0.0f) ? ENTITY_ACC : -ENTITY_ACC;
            entities.acc.y = (delta_y > 0.0f) ? ENTITY_ACC : -ENTITY_ACC;
        }

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

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

Posted: Wed Jan 03, 2018 6: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: http://higherorderfun.com/blog/2012/05/ ... atformers/