Discussion in 'Programming' started by Aite, Jan 15, 2020.

  1. Aite

    Aite Member

    Jan 13, 2020
    Hello how can i make one object move to a given position. For example car is driving in a 3 lane road and I want it to move from middle to right with just one right key pressed. I dont want it to move pixel by pixel to one position just to like teleport there.
  2. Binsk

    Binsk Member

    Jun 22, 2016
    There are two built-in variables for every object called x and y.

    You can read them to get the object's position in the room but they can also be set which will 'warp' the object to a location.

    That is what you want to use.
  3. robproctor83

    robproctor83 Member

    Sep 30, 2019
    Like Binsk said, x and y are the objects coordinates, you can move the object around with those variables. - is left and + right, - is up and + is down. Your condition about having an object teleport between three lanes would be relatively simple. The easiest way would be to create your object, presumably a car, and in that object add events for create, step and key press left and key press right as well as making a new script call scr_swap_lanes. Then in create add

    I haven't tested any of this, just spit balling, but something like this should work.
    x = 100 + (32 * lane)
    #key left
    lane = scr_swap_lanes(-1);
    #key right
    lane = scr_swap_lanes(1);
    var _lane_move = argument[0];
    return clamp(lane+_lane_move , 0, 2);
    You would also want to add roads and stuff. But essentially you would just need to store a variable that controls which lane the object should be in, then you offset the object by some amount so that it is positioned over the roads left lane (in the example above in the step that is what the 100 is for). Then you multiply the width of the lane by the lane your on (that is what the 32 is for). The new lane swap script just lets you pass how many lanes and what direction it should shift, and then it clamps that value with lane so that it doesn't go over 2 or under 0 (which would be for a total of 3 lanes).

    Best of luck

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice