S
SoftwenOP
Guest
I'm currently messing around with a project in GMS 1.4. I've successfully implemented a mechanic which allows the player to pick up and throw objects. However, I've experienced difficulties getting the object to have proper knockback, or a bounce feature when colliding with an object while being thrown. I've tried various methods to no avail. If anything does happen, the object either goes into the opposite direction, but doesn't stop, or stops, but goes in the incorrect direction. This is the movement code of the object, held within the step event:
///Follow Player
if Stick = true {
x = obj_player.x;
y = obj_player.y;
}
//Be Thrown
if Dir1 = true {
move_towards_point(x, y+Spd, Spd);
}
if Dir2 = true {
move_towards_point(x, y-Spd, Spd);
}
if Dir3 = true {
move_towards_point(x+Spd, y, Spd);
}
if Dir4 = true {
move_towards_point(x-Spd, y, Spd);
}
This is the code which allows the player to throw the object:
///Throw
if place_meeting(x, y, obj_rock) {
var ID;
ID = instance_nearest(x, y, obj_rock);
if Facing = 1 && ID.Stick = true {
ID.Dir1 = true;
ID.Spd = 6;
ID.Stick = false;
}
if Facing = 2 && ID.Stick = true {
ID.Dir2 = true;
ID.Spd = 6;
ID.Stick = false;
}
if Facing = 3 && ID.Stick = true{
ID.Dir3 = true;
ID.Spd = 6;
ID.Stick = false;
}
if Facing = 4 && ID.Stick = true {
ID.Dir4 = true;
ID.Spd = 6;
ID.Stick = false;
}
}
The main method I tried was setting Spd to equal -6 upon collision with a static object, then while Spd is below zero, use the lerp function to try and slow it down until Spd is equal to zero. I'm open to any suggestions, even if it involves changing this code.
///Follow Player
if Stick = true {
x = obj_player.x;
y = obj_player.y;
}
//Be Thrown
if Dir1 = true {
move_towards_point(x, y+Spd, Spd);
}
if Dir2 = true {
move_towards_point(x, y-Spd, Spd);
}
if Dir3 = true {
move_towards_point(x+Spd, y, Spd);
}
if Dir4 = true {
move_towards_point(x-Spd, y, Spd);
}
This is the code which allows the player to throw the object:
///Throw
if place_meeting(x, y, obj_rock) {
var ID;
ID = instance_nearest(x, y, obj_rock);
if Facing = 1 && ID.Stick = true {
ID.Dir1 = true;
ID.Spd = 6;
ID.Stick = false;
}
if Facing = 2 && ID.Stick = true {
ID.Dir2 = true;
ID.Spd = 6;
ID.Stick = false;
}
if Facing = 3 && ID.Stick = true{
ID.Dir3 = true;
ID.Spd = 6;
ID.Stick = false;
}
if Facing = 4 && ID.Stick = true {
ID.Dir4 = true;
ID.Spd = 6;
ID.Stick = false;
}
}
The main method I tried was setting Spd to equal -6 upon collision with a static object, then while Spd is below zero, use the lerp function to try and slow it down until Spd is equal to zero. I'm open to any suggestions, even if it involves changing this code.