GML How to get player out of car door when car at angle?

Z

zakthdrgnslyer

Guest
So when you're driving, the car's sprite changes image angle when it turns. How would I get the player to come out of the correct side of the car when you exit?
Here's my code.
Create event:
Code:
instance_create_layer(x,y,"Mechanics",obj_car_hitbox)
turndspeed = 2;
maxdspeed=7.10
accspeed=.2
brakespeed=.2
maxrspeed = -3
Step event:
GML:
if obj_player.state = "driving"{
friction = .1
//Accelerate
if (keyboard_check(ord("W"))){
    speed = (speed + accspeed);
}
//Brake
if (keyboard_check(ord("S"))){
    speed = (speed - brakespeed);
}
//Keeps car at the max speed
if (speed >= maxdspeed) speed = maxdspeed;
if (speed <= maxrspeed) speed = maxrspeed;

//Turning the car
if (speed != 0){
    if (keyboard_check(ord("A"))){
        direction += turndspeed;
        image_angle += turndspeed
        }
    if (keyboard_check(ord("D"))){
        direction -= turndspeed;
        image_angle -= turndspeed;
        }
}
//Get player out of the car
if keyboard_check_pressed(ord("E")){
    obj_player.state="idle"
    obj_player.move_speed=obj_player.init_move_speed;
    instance_destroy(obj_car_hitbox)
    alarm[0]=5
    }
}
Alarm[0]:
Code:
instance_create_layer(x,y,"Mechanics",obj_car_hitbox)
 
For the distance argument, make it long enough to go from the center of the car to the spot outside the door. For the angle argument, take the direction and add 90 (or subtract 90, depending on which side is the driver's). Make sure the arguments match for both x and y functions.
 
Z

zakthdrgnslyer

Guest
For the distance argument, make it long enough to go from the center of the car to the spot outside the door. For the angle argument, take the direction and add 90 (or subtract 90, depending on which side is the driver's). Make sure the arguments match for both x and y functions.
it doesn't work, it just sends me extremely far away from the car.
In the step event of the car:
GML:
obj_player.y = lengthdir_y(y-20,direction-90)
 

Joe Ellis

Member
You're using it wrong, the length should be how much\far away from the car you want it to be, so if you use y, it could be like 2500 or something. That's where the problem is.
It should be about the same as the width of the car divided by 2, so it'll come from the center of the car and appear at the side
 
Yeah, the length is how far away from the car. You still need to add the y, but outside of the function - or you can just add the result of this to the player's y instead of directly setting it.
 
Z

zakthdrgnslyer

Guest
You're using it wrong, the length should be how much\far away from the car you want it to be, so if you use y, it could be like 2500 or something. That's where the problem is.
It should be about the same as the width of the car divided by 2, so it'll come from the center of the car and appear at the side
it doesn't work, it just sends me extremely far away from the car.
In the step event of the car:
GML:
obj_player.y = lengthdir_y(y-20,direction-90)
I fixed it with. Thank you guys for the help!
GML:
var xx = lengthdir_x(40,direction+90)
var yy = lengthdir_y(-40,direction-90)
obj_player.x = obj_player.x + xx
obj_player.y = obj_player.y + yy
 
Top