• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Elastic Slingshot problem

M

MarkyzZz

Guest
Hello. I need some help in creating an elastic slingshot, that on collision with the player, would throw him away towards a point in the opposite direction of collision.I'm not using any built in variables to control gravity and speed, nor do i use physics for this. So, basically this is what i've done atm:

Create Event of Slingshot:
Code:
/*This is some algebra that would calculate how much speed he needs to move horizontally and vertically to get to that point*/
xx=x+lengthdir_x(200,0);
yy=y-lengthdir_y(200,0);

travel_speed=5;
vx=xx-x;
vy=yy-y;
len=sqrt(sqr(vx)+sqr(vy));

vx=vx/len;
vy=vy/len;

speed_x=vx*travel_speed;
speed_y=vy*travel_speed;
Step Event:

Code:
//I set an alarm and while the alarm is active the player moves
// When the alarm stops the player does not move
if(place_meeting(x+1,y,obj_Player)){
    alarm_set(0,room_speed*2);
}
if(alarm[0]){
    with(obj_Player){
        x+=obj_el_slingshot.speed_x;
        y-=obj_el_slingshot.speed_y;
    }
}
Alarm Event for alarm 0:
Code:
speed_x=0;
speed_y=0;
The problem: When i collide with the slingshot for the first time, it throws me away horizontally and the player stops after 2s. But if i collide again with it, it doesn't throw me back anymore. How do i fix that? or how can i make a better slingshot, without using built-in physics?
 
J

jackhigh24

Guest
is it a slingshot or trampoline ?

sound like you want to bounce of it when you run into it
you could just do it a very simple way like this
put this in player, in a collision event with slingshot thing
Code:
move_towards_point(xprevious,yprevious,5);
thats it really, then you can have an alarm to set speed back to 0 after the 2 seconds like you need
if your using keyboard controls to move that player thing around then you would have to do in step event ( example )
Code:
if !place_meeting(x,y,oCatapult)
{
if keyboard_check(ord('A'))
{
x-=2;
}
if keyboard_check(ord('D'))
{
x+=2;
}
if keyboard_check(ord('W'))
{
y-=2;
}
if keyboard_check(ord('S'))
{
y+=2;
}
}
rubbish example of key control but will do to explain this
 
M

MarkyzZz

Guest
is it a slingshot or trampoline ?

sound like you want to bounce of it when you run into it
you could just do it a very simple way like this
put this in player, in a collision event with slingshot thing
Code:
move_towards_point(xprevious,yprevious,5);
thats it really, then you can have an alarm to set speed back to 0 after the 2 seconds like you need
if your using keyboard controls to move that player thing around then you would have to do in step event ( example )
Code:
if !place_meeting(x,y,oCatapult)
{
if keyboard_check(ord('A'))
{
x-=2;
}
if keyboard_check(ord('D'))
{
x+=2;
}
if keyboard_check(ord('W'))
{
y-=2;
}
if keyboard_check(ord('S'))
{
y+=2;
}
}
I forgot to mention that i have already tried with move_towards_point() function and it doesn't even move my player. Sorry. For movement control i have the left right keys. Generally speaking, i'm developing a platform game and i want a slingshot and when the player gets into it, it will throw him away. Like very hard.
 
J

jackhigh24

Guest
thats weird why does it not even move your player, you need to give more details, that simple way of doing it works, cant understand why your player wont move using that function, it should if you have a normal room and not a physics room.
 
M

MarkyzZz

Guest
thats weird why does it not even move your player, you need to give more details, that simple way of doing it works, cant understand why your player wont move using that function, it should if you have a normal room and not a physics room.
Well its a normal room, but, i have physics enabled in it. I don't use the build in hspeed,vspeed and so on. All the movement is controled by created variables but there are some moments in the Game where i need to enable physics and switch from a non-physics using instance to a physics-using one. That's why in the room it's toggled on.
 
Top