GameMaker GMS2 acceleration_to_point

E

EnSea

Guest
Alright, here's something I thought could be extremely useful IF I could ever figure out how to make it.
A piece of code where an object moves from one point to another smoothly without just jumping to the co-ordinates.
This is the base I'm working with.
Any ideas on how to continue this?
(I'm new to GMS2 so I don't know if this is already possible to do with some other code that I havent seen yet.)
GML:
/// @desc acceleration_to_point(from,to,speed);
/// @arg from
/// @arg to
/// @arg speed
 

Nidoking

Member
How is that any different from gravity/acceleration? Your instance is going to "jump" from one location to another location at every step unless it doesn't move at all. That's how pixels and steps work.
 
E

EnSea

Guest
How is that any different from gravity/acceleration? Your instance is going to "jump" from one location to another location at every step unless it doesn't move at all. That's how pixels and steps work.
I'm trying to get it to move, not jump. Because I can't seem to make an object move on collision, without it going to a different part of the screen in a single jump.
 

FoxyOfJungle

Kazan Games
I've tried to use this but it always confuses me ;-;
An example use of lerp:

GML:
variable = lerp(variable, 10, 0.2);
This will make the variable go to 10 smoothly, with a speed of 0.2 percent.
There is also a script that makes one variable "go to another" using a speed:

GML:
/// @func Approach(val1, val2, amount)
/// @param val1
/// @param val2
/// @param amount
// Moves "a" towards "b" by "amount" and returns the result

if (argument0 < argument1)
{
    return min (argument0 + argument2, argument1);
}
else
{
    return max (argument0 - argument2, argument1);
}
 

Nidoking

Member
I'm trying to get it to move, not jump. Because I can't seem to make an object move on collision, without it going to a different part of the screen in a single jump.
Sounds like your collision code is the problem, then. Moving is, literally, exactly jumping from one location to another. If the movement is little enough per step, it may appear smooth due to the processing speed of the vision center in the human brain and the poor acuity of the eye relative to the number of frames drawn per second.
 
E

EnSea

Guest
An example use of lerp:

GML:
variable = lerp(variable, 10, 0.2);
This will make the variable go to 10 smoothly, with a speed of 0.2 percent.
There is also a script that makes one variable "go to another" using a speed:

GML:
/// @func Approach(val1, val2, amount)
/// @param val1
/// @param val2
/// @param amount
// Moves "a" towards "b" by "amount" and returns the result

if (argument0 < argument1)
{
    return min (argument0 + argument2, argument1);
}
else
{
    return max (argument0 - argument2, argument1);
}
Does this jump or move? if so, is it to coordinates or direction. i shouldve explained that im trying to get objects to move in a direction a certain amount.
 

FoxyOfJungle

Kazan Games
Does this jump or move? if so, is it to coordinates or direction. i shouldve explained that im trying to get objects to move in a direction a certain amount.
Have you tried using lenghtdir_x() and lenghtdir_y()?
GML:
x += lenghtdir_x(speeed, directionn);
y += lenghtdir_y(speeed, directionn);
Do not use the built-in "direction" and "speed" variables.
 
E

EnSea

Guest
Have you tried using lenghtdir_x() and lenghtdir_y()?
GML:
x += lenghtdir_x(speeed, directionn);
y += lenghtdir_y(speeed, directionn);
How would i make the dir equal to the opposite direction of the collision?
 

woods

Member
this is from GMS1 manual, but the concept still applies..



if point_distance(x, y, target.x, target.y) > 5
{
move_towards_point(target.x, target.y, 5);
}
else speed = 0;
 

FoxyOfJungle

Kazan Games
How would i make the dir equal to the opposite direction of the collision?
I think things could be simpler if you use the friction function.
But, it would also be interesting to have a screenshot of your game or project so that we can give a better solution, it is not very clear yet what you want to do, is it a spaceship game? RPG?
Do you want the character to move smoothly from one place to another?

It all depends on how your game is being made, so we can analyze what is the best way to do something.
 
E

EnSea

Guest
I think things could be simpler if you use the friction function.
But, it would also be interesting to have a screenshot of your game or project so that we can give a better solution, it is not very clear yet what you want to do, is it a spaceship game? RPG?
Do you want the character to move smoothly from one place to another?

It all depends on how your game is being made, so we can analyze what is the best way to do something.
1597636242235.png
the code i need is to push back the slime when it is attacked with fireball sent by the player
 

FoxyOfJungle

Kazan Games
Got it, depending on how you made the slide motion code, you can use lenghtdir_x() and lenghtdir_y()
Now you will have to do it by subtracting:

GML:
x -= lenghtdir_x(speeed, directionn);
y -= lenghtdir_y(speeed, directionn);
I'm guessing. Post all the slime code here so that we can understand how it moves.
 
E

EnSea

Guest
Got it, depending on how you made the slide motion code, you can use lenghtdir_x() and lenghtdir_y()
Now you will have to do it by subtracting:

GML:
x -= lenghtdir_x(speeed, directionn);
y -= lenghtdir_y(speeed, directionn);
I'm guessing. Post all the slime code here so that we can understand how it moves.
Create:
GML:
widthScreen = 1024;
heightScreen = 768;
player = object_Character1;
block = object_Wall
Screen = widthScreen + heightScreen;
slimeHP  = 5;

hSpeed = speed;
vSpeed = speed;
Step:

GML:
if distance_to_object(player)<=Screen{    //gives sight
      if (collision_line(x,y,player.x,player.y,block,true,true) = noone) {
           direction=point_direction(x,y,player.x,player.y);
           speed = 1; //sets the speed of the enemy
    }
}

if (slimeHP <= 0)
{
    instance_deactivate_object(object_Slime);
    instance_create_layer(x,y,layer,object_Heart);
}
collision(object_FireballDown):
(its the same with each collision event for each fireball object)
GML:
slimeHP -= 1;
instance_deactivate_object(instance_nearest(x,y,object_FireballDown));
 
Top