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:
Step Event:
Alarm Event for alarm 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?
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;
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;
}
}
Code:
speed_x=0;
speed_y=0;