FreshRSS

Zobrazení pro čtení

Jsou dostupné nové články, klikněte pro obnovení stránky.

Predictive Aim to shoot a moving target with a constant velocity while the projectile is affected by gravity (2D/Platformer view)

I've been working on creating stationary gun turrets that can shoot down missiles in my game. The bullets are affected by gravity while the missile moves in a linear path at a constant rate as if it had no acceleration or gravity. A turret shooting bullets in a parabolic curve at a missile moving in a straight path

Here is the math for the prediction My math is most likely wrong because it doesnt work even after I've tweaked and changed a few things.

Could someone please explain the derivation of the correct formula?

How to rotate 2D arm around shoulder so gun points at cursor?

I'm trying to program 2D mouse aim, where the arms and the gun in the arms rotates to point at the mouse. But for some reason, the arms and gun rotate and do not follow the mouse position.

The each of the arms and the guns are separate node that are parented to an orbit node that is located on at the shoulder of the arms.

The following code is script that is attached and running on the orbit.

    var mousePos = get_viewport().get_mouse_pos();
    var dir = get_pos();
    var angle = (atan2(dir.x,dir.y))+(2*PI);
    var arm_gun_dir = gravGun_Ref.get_pos()-get_pos();
    var arm_gun_angle = (atan2(arm_gun_dir.x,arm_gun_dir.y))+(2*PI);
    set_rot(angle-(PI/2));

Here is a GIF of the result of this setup: enter image description here

Here is an image showing where the positions of the upper arm and the gun.

animated clip of result

❌