GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2016-01-19 11:44:44

lostdarkwolf
Member
Registered: 2015-11-19
Posts: 23

My WIP Scripts (work in progress)

couldnt think of anywhere to put my WIP's so i put them here with details of whats going on with each script. this is for backup, debug, and presentation.

completed script that is part of a collision system WIP.

///wiggle(wiggle_dist, inst*)
// * argument is optional
//
// tries to wiggle an object free of an instance. (one distance set, at a time.)
// returns true if successful.
//
// wiggle_dist    ammount in pixels of the position change.
// inst           instance or object to wiggle from, set to -1 to wiggle from solids.
//
/// GMLscripts.com/license

ii_distance=argument[0];
ii_inst=-1;
if argument_count>1 var ii_inst=argument[1];

// overhead view, you are X.
// 7 8 9
// 4 X 6
// 1 2 3
// order is X64283719

if ii_inst!=-1 {
 if !place_meeting(x,y,ii_inst) {return 1;} // X
 if !place_meeting(x+ii_distance,y,ii_inst) {x+=ii_distance; return 1;} // 6
 if !place_meeting(x-ii_distance,y,ii_inst) {x-=ii_distance; return 1;} // 4
 if !place_meeting(x,y+ii_distance,ii_inst) {y+=ii_distance; return 1;} // 2
 if !place_meeting(x,y-ii_distance,ii_inst) {y-=ii_distance; return 1;} // 8
 if !place_meeting(x+ii_distance,y+ii_distance,ii_inst) {y+=ii_distance; x+=ii_distance; return 1;} // 3
 if !place_meeting(x-ii_distance,y-ii_distance,ii_inst) {y-=ii_distance; x-=ii_distance; return 1;} // 7
 if !place_meeting(x-ii_distance,y+ii_distance,ii_inst) {y+=ii_distance; x-=ii_distance; return 1;} // 1
 if !place_meeting(x+ii_distance,y-ii_distance,ii_inst) {y-=ii_distance; x+=ii_distance; return 1;} // 9
}
else {
 if place_free(x,y) {return 1;} // X
 if place_free(x+ii_distance,y) {x+=ii_distance; return 1;} // 6
 if place_free(x-ii_distance,y) {x-=ii_distance; return 1;} // 4
 if place_free(x,y+ii_distance) {y+=ii_distance; return 1;} // 2
 if place_free(x,y-ii_distance) {y-=ii_distance; return 1;} // 8
 if place_free(x+ii_distance,y+ii_distance) {y+=ii_distance; x+=ii_distance; return 1;} // 3
 if place_free(x-ii_distance,y-ii_distance) {y-=ii_distance; x-=ii_distance; return 1;} // 7
 if place_free(x-ii_distance,y+ii_distance) {y+=ii_distance; x-=ii_distance; return 1;} // 1
 if place_free(x+ii_distance,y-ii_distance) {y-=ii_distance; x+=ii_distance; return 1;} // 9
}

like the script above, this is part of a collision system WIP and is complete.

///direction_fix(inst*, angular_precision*, direction_flux_cap*)
// * all arguments are optional
//
// corrects the direction of the calling instance to not collide with the target instance (or object).
// returns weather successful
//
// inst                  instance to avoid, set to -1 to avoid solids.
// angular_precision     precision for checking for empty spots
// direction_flux_cap    cap for direction change
//
/// GMLscripts.com/license

var ii_inst, SCRprec, SCRlimit;
ii_inst=-1;
if argument_count>0 ii_inst=argument[0];
SCRprec=2;
if argument_count>1 SCRprec=argument[1];
SCRlimit=90;
if argument_count>2 SCRlimit=argument[2];


if ii_inst!=-1 {
 if place_meeting(x+lengthdir_x(speed,direction),y+lengthdir_y(speed,direction),ii_inst) {
  //smooth movement
  for(ii=0; ii<=SCRlimit; ii+=SCRprec;){
   if(!place_meeting(x+lengthdir_x(speed,direction+ii),y+lengthdir_y(speed,direction+ii),ii_inst)) {
    direction+=ii;
    ii=90+1;
    return true;
   }
   if(!place_meeting(x+lengthdir_x(speed,direction-ii),y+lengthdir_y(speed,direction-ii),ii_inst) and
      ii<=90) {
    direction-=ii;
    ii=90+1;
    return true;
   }
  }
 }
 return false;
}
else {
 if !place_free(x+lengthdir_x(speed,direction),y+lengthdir_y(speed,direction)) {
  //smooth movement
  for(ii=0; ii<=SCRlimit; ii+=SCRprec;){
   if(place_free(x+lengthdir_x(speed,direction+ii),y+lengthdir_y(speed,direction+ii))) {
    direction+=ii;
    ii=90+1;
    return true;
   }
   if(place_free(x+lengthdir_x(speed,direction-ii),y+lengthdir_y(speed,direction-ii)) and
      ii<=90) {
    direction-=ii;
    ii=90+1;
    return true;
   }
  }
 }
 return false;
}

this script is INCOMPLETE and will be added to my collision system when it is done.

///move_against_3d(object_index, angle_precision*)
// * not required
//
// moves the calling instance smoothly around other solid instances.
// every solid and calling instance MUST have certain variables: z and zsize.
//   z should be the instances z position.
//   zsize should be the size of the instance's mask on the z axis
// any solid object outside the calling instance's specified z location will not be considered solid.
// includes position correction to try to keep the instance from getting stuck.
//
// z_flux_cap   cap for distance allowed for changing the calling instance's z position. in turn, allowing it to get on top of another short solid object, like a stair.
// cliff_walk   trigger for allowing the calling instance to walk off of a sudden dropoff.
// angle_prec   angular precision for moving smoothly.
// wiggle_cap   cap for position correction distance.
// wiggle_prec  precision for position correction.
//
// solids dont act solid by default in any way, unless you use the physics engine (i think). (with latest GM version)
// example; if the mask is a circle, then the collision box will be a cylinder.
//
///gmlscripts.com

var ii, SCRprec, SCRwig_cap, SCR;
SCRz_flux=
SCRcliff_walk
SCRprec=2; if argument_count>0 SCRprec=argument[0]
SCRwig_cap=30; if argument_count>1 SCRwig_cap=argument[1]
SCRwig_prec=2; if argument_count>2 SCRwig_prec=argument[2]

if !place_free(x+lengthdir_x(speed,direction),y+lengthdir_y(speed,direction)) {
 //smooth movement
 for(ii=0; ii<=90; ii+=SCRprec;){
  if(place_free(x+lengthdir_x(speed,direction+ii),y+lengthdir_y(speed,direction+ii))) {
   direction+=ii;
   ii=90+1;
  }
  if(place_free(x+lengthdir_x(speed,direction-ii),y+lengthdir_y(speed,direction-ii)) and
     ii<=90) {
   direction-=ii;
   ii=90+1;
  }
 }
 
 // wiggle free if needed
 if !place_free(x,y) {
  for (ii=1; ii<SCRwig_cap; ii+=SCRwig_prec;) {
   wiggle(ii);
   if place_free(x,y) return true;
  }
 }
 else return true;
}

this script is part of an ai example WIP and is complete.

///collision_fov(look_x,look_y,look_dir,look_fov,look_view_dist,target_x,target_y,solid_obj);
var TXXX,TYYY,LXXX,LYYY,LDIR,SOBJ,SFOV,LVDI,OFSX,OFSY,playerDir;
LXXX=argument0; // looker x
LYYY=argument1; // looker y
LDIR=argument2; // looker direction
LFOV=argument3; // looker fov
LVDI=argument4; // looker view distance
TXXX=argument5; // target x
TYYY=argument6; // target y
SOBJ=argument7; // solid parent or block

playerDir = point_direction(LXXX,LYYY,TXXX,TYYY);//direction from looker to target
//if player is within guard's field of vision
if abs(angle_difference(playerDir,LDIR))<LFOV {
  //if player is within guard's sight distance
  if point_distance(LXXX,LYYY,TXXX,TYYY)<=LVDI {
    //if there is no solid (wall) between guard and player
    if !collision_line(TXXX,TYYY,LXXX,LYYY,SOBJ,true,true) {
      return 1;
      exit;
    }
  }
}
return 0;

Last edited by lostdarkwolf (2016-01-19 17:29:11)

Offline

Board footer

Powered by FluxBB