Skip to content

Weapon dot-to-target input#7285

Open
Kestrellius wants to merge 3 commits intoscp-fs2open:masterfrom
Kestrellius:weapon-dot-inputs
Open

Weapon dot-to-target input#7285
Kestrellius wants to merge 3 commits intoscp-fs2open:masterfrom
Kestrellius:weapon-dot-inputs

Conversation

@Kestrellius
Copy link
Copy Markdown
Contributor

Adds a weapon lifetime input that consists of the dot product between the vector that points toward the current target and the weapon's forward vector.

@wookieejedi wookieejedi added the enhancement A new feature or upgrade of an existing feature to add additional functionality. label Mar 14, 2026
{
if (!IS_VEC_NULL(&wp.homing_pos)) {
target_pos = wp.homing_pos;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this could happen, but if homing_object is valid but IS_VEC_NULL(&wp.homing_pos) is true, the inner if body is skipped, target_pos is never assigned, and the function eventually hits vm_vec_sub with bad data. Could fix this by adding an else return 0.f, IE

     } else {
            return 0.f;
        }

return 0.f;
}
vec3d dir;
vm_vec_sub(&dir, &wep_objp->pos, &target_pos);
Copy link
Copy Markdown
Member

@wookieejedi wookieejedi Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should dir be normalized? I think vm_vec_dot on an unnormalized `dir gives a distance-scaled projection, which seems like that isn't the intent? Normalizing before the dot would fix this I reckon...IE

vm_vec_normalize(&dir);
return vm_vec_dot(&dir, &wep_objp->orient.vec.fvec);
``

return 0.f;
}
vec3d dir;
vm_vec_sub(&dir, &wep_objp->pos, &target_pos);
Copy link
Copy Markdown
Member

@wookieejedi wookieejedi Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says dot product between the vector that points toward the current target and the weapon's forward vector. Just want to check, are these in the right order? I think dir = weapon - target points away from the target not towards it (so switching to target_pos - wep_objp->pos` would face torwards) but perhaps someone with better dot math can chime in. @Baezon perhaps :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A new feature or upgrade of an existing feature to add additional functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants