简体   繁体   中英

Gamemaker dcos() and dsin() for drawing aim

the gif will better explain what I'm trying to do. Bow aim.

as you can see I can't get the arrow to follow the aim. The problem is I have the Bow and Arrow separate so the bow spawns the arrow and that's the problem I can't get the calculation of the hspeed and vspeed and gravity of the arrow to match the bow draw event of the doted aim. I will post the doted aim code and the arrow gravity/movement code the spawn code for the arrow is simple on the release of the button it spawns the arrow at the x,y position of the bow. If you need any other code I will post it. Sorry if it's not well explained.

Arrow Code: End Step

///Check if parent still exists
if (parent != noone)
if (!instance_exists(parent))
{
    parent = noone;
}

///Gravity
if (grav != 0)
{
    hsp += lengthdir_x(grav, grav_dir);
    vsp += lengthdir_y(grav, grav_dir);
}

///Increase gravity over time, up until a maximum amount
grav = min(grav+grav_add, grav_max);

///Limit speed
hsp = clamp(hsp, -hsp_max, hsp_max);
vsp = clamp(vsp, -vsp_max, vsp_max);

///Calculate directional speed
var sp = point_distance(0, 0, hsp, vsp);
direction = point_direction(0, 0, hsp, vsp);

Bow:

DrawEvent:

var _f_x = x;
var _f_y = y;
var _f_spd_x = draw_aim_circle_max * dcos(controler_angle)
var _f_spd_y = draw_aim_circle_max *-dsin(controler_angle)

while (!instance_place(_f_x,_f_y,objAimCircleKiller))
    {
        draw_sprite(sprAimCircleSmall,0,_f_x,_f_y+1);
                        _f_x += _f_spd_x
                        _f_spd_y += grav_aimCircle 
                        _f_y += _f_spd_y;
    }
    

Do you have some code in Arrow to slowdown the horizontal speed? It seems to stop faster than it should. Try to use a different variable to manage the horizontal speed instead of the grav var. When calculate the x speed of the arrow, define an explicit value max speed. The arrow speed should be max speed when the sin angle is 90° and close to 0 when sin angle is 0. Then just use the arcsin function to get a value from 0/1 and multiply for the max speed.

    var maxHorSpeed = 10;
    var aimAngle = lengthdir_y(bow.x,bow.y,target.x,target.y);
    
    arrow.horizontalSpeed = clamp( sin(aimAngle)*maxHorSpeed,0.2, maxHorSpeed);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM