T
Toxicosis
Guest
I'm still working on a prototype to gain experience.
In this prototype, the player can GRAB things during a collision event with their hands, and then throw them away. I have a problem, though- I made the player able to grab wall segments. However, rather than make them disappear, I placed them on the player's hand.
And that's a problem, because the wall segments prevent the player from moving in the wall's direction very quickly, or in the other direction at all- turning around forces the segment to overlap the player, and thus, no movement in any direction is possible.
I tried to disable the mask for that instance alone while the player is grabbing, but that caused a problem of its own: the objects the player grabs no longer have a sprite while grabbed, and while that did nothing to the walls, the enemies have a draw event that fails if they have no sprite. Can anyone spot the mistake? I've spent the whole Sunday on this, I no longer really know what's what.
I tried saving the sprite index to a control object, then duplicating it with an inexistent mask, which gets assigned to the particular instance the player has in hand. After the player releases the object, the control object restores the grabbed instance's initial sprite. A lot of it was trial, error... flailing, really. I've got no clue what's wrong in this code anymore.
Code for grabbing:
Code for releasing:
In this prototype, the player can GRAB things during a collision event with their hands, and then throw them away. I have a problem, though- I made the player able to grab wall segments. However, rather than make them disappear, I placed them on the player's hand.
And that's a problem, because the wall segments prevent the player from moving in the wall's direction very quickly, or in the other direction at all- turning around forces the segment to overlap the player, and thus, no movement in any direction is possible.
I tried to disable the mask for that instance alone while the player is grabbing, but that caused a problem of its own: the objects the player grabs no longer have a sprite while grabbed, and while that did nothing to the walls, the enemies have a draw event that fails if they have no sprite. Can anyone spot the mistake? I've spent the whole Sunday on this, I no longer really know what's what.
I tried saving the sprite index to a control object, then duplicating it with an inexistent mask, which gets assigned to the particular instance the player has in hand. After the player releases the object, the control object restores the grabbed instance's initial sprite. A lot of it was trial, error... flailing, really. I've got no clue what's wrong in this code anymore.
Code for grabbing:
Code:
//When the pinch grabs an enemy, the enemy must resort to behaviour 101. Then we must make the pinch change behaviour itself.
//Change: when the pinch grabs an instance, their ID is stored in a control object that we create. Hold becomes true, too.
//if hold == true exit;
var grab;
grab = noone;
if hold == true exit;
if place_meeting(x,y,obj_enemy) //If it touches an enemy
{
with obj_enemy
{
if sticking == 1 //Check that the enemy's not sticking to the player.
exit;
}
with other //Back to the player,
hold=true; //start holding.
with obj_enemy //Back to the enemy,
{
if place_meeting(x,y,obj_pinch) //If there's one hitting the player's hand
{
abnormal_behaviour = 101; //abnormal behaviour 101.
grab = id; //Mark it under grab.
}
}
}
if place_meeting(x,y,obj_wallz_pick_up) //If it touches a pickuppable wall,
{
hold=true; //also held. Check the walls for one that's in position.
with obj_wallz_pick_up
{
if place_meeting(x,y,obj_pinch)
grab = id; //Mark it as grabbed.
}
}
if grab != noone //Did we grab something? Create a grab instance of control_throw, and tell it to file them.
{
grabb = instance_create(x,y,obj_control_throw); //Create the control object.
grabb.inst = grab; //Make it point to the object we're grabbing.
grabb.grabbing = true; //Tell it we're grabbing that thing right now.
grabb.spr_store = grabb.inst.sprite_index; ///Store the current index.
if sprite_exists(spr_throw) sprite_delete(spr_throw); //Clears spr_throw.
grabb.spr_throw = sprite_duplicate(grabb.inst.sprite_index); //Assigns spr_throw the current sprite of the grabbed instance.
sprite_collision_mask(spr_throw, false, 1, sprite_width/2, sprite_height/2, sprite_width/2, sprite_height/2, 1, 0); //Assigns that same sprite a pretty empty collision mask.
var sprite_throw; //Readies a variable to pass things to inst.
sprite_throw = spr_throw; //Assigns the variable to spr_throw.
with grabb.inst
{
sprite_index = sprite_throw; //Assigns the sprite to the object.
}
}
Code:
//So long as there's a pinch, inst must remain in that position.
var fall = 5;
if grabbing == true
{
fling_direction = obj_player.facing;
fling_speed = sprite_get_width(spr_punch)/2;
}
if instance_exists(inst) && instance_number(obj_pinch) == 1 && grabbing == true
{
with inst
prep_hurl()
exit;
}
//Once the pinch is out, we're no longer grabbing.
if instance_number(obj_pinch) == 0
{
var sprite_store; //Creates the variable.
sprite_store = spr_store; //Stores the variable.
with inst sprite_index = sprite_store; // restores the sprite to the value that had been stored before.
grabbing = false; //Grabbing is no longer its initial value.
}
//Which means we're flying.
if instance_exists(inst) && grabbing == false
{
grabbing = false;
// if !be_flung(fall,fling_speed/4,fling_direction,inst) //I made a script because I was getting tired of typing the whole thing all the time. It returns false if it can't move.
if !be_flung(fall,fling_speed,fling_direction,inst)
instance_destroy(); //If the thing we want to throw cannot fly anymore, no need for this.
}