need help with some movement

Discussion in 'Programming' started by vaultapple, Nov 20, 2017.

  1. vaultapple

    vaultapple Member

    Joined:
    Nov 4, 2017
    Posts:
    7
    hi i am having a similar problem and could use a new set of eyes as well as help.

    ///the square with the turn is the issue
    [​IMG]
    ///the code works some of the time depending on the speed of car witch is in alarm 0
    ///left pressed starts alarm 0
    if speed < 10
    {
    direction = direction
    speed += .5
    alarm[1] = 0
    alarm[0] = 24
    }
    ///alarm 1 is the opposite to slow the car
    ///left released starts alarm 1

    ///the code that makes the car turn is in step event
    if x >= obj_tile_31_left_up.x + 73
    {
    if x <= obj_tile_31_left_up.x + 82
    if direction = 90
    {exit}
    direction += 10
    image_index += 10
    }
     
  2. lindens

    lindens Member

    Joined:
    Oct 9, 2017
    Posts:
    20
    1) You should really format your post so that the code is more readable
    2) I wouldn't recommend using alarms, making a variable that triggers after x amount of steps is much more concise imo
    3) What is the issue exactly lol
     
    Badger and maratae like this.
  3. nesrocks

    nesrocks Member

    Joined:
    Nov 6, 2016
    Posts:
    305
    I think he wants to program an AI. This is very much unclear.
     
  4. vaultapple

    vaultapple Member

    Joined:
    Nov 4, 2017
    Posts:
    7
    Ok thanks for the help I will try and start again.
    there are two objects in use a car, obj_car and a tile obj_tile_31_left_up .
    the image blow shows obj_car and obj_tile_31_left_up, with a start point and an end point.

    upload_2017-11-20_17-39-56.png
    the sprite of obj_tile_31_left_up is 200,200 pixels and origin is 0,0
    the sprite of obj_car is 40,40 pixels and origin is 20,20

    the start point is at obj_tile_31_left_up.x +73 where obj_car direction and image angle should start to increase by ten.
    the end point is at obj_tile_31_left_up.x + 82 where obj_car direction and image angle should now be at ninety degrees.

    the code blow in the step event of obj_car is what should make obj_car start to and end the turn.
    ///obj_car step event
    if instance_exists(obj_tile_31_left_up)
    {
    if x >= obj_tile_31_left_up.x + 73 && x <= obj_tile_31_left_up.x + 82
    {
    if direction = 90
    {exit}
    direction += 10
    image_index += 10
    }
    }

    the main issue is the speed of obj_car if going to fast the turn will be missed, when going to slow the obj_car turns to soon.
    in the alarms blow shows how to speed is handled.
    ///obj_car alarm 0
    if speed < 10
    {
    direction = direction
    speed += .5
    alarm[1] = 0
    alarm[0] = 24
    }
    ///obj_car alarm 1
    if speed > 0
    {
    direction = direction
    speed -= .5
    alarm[0] = 0
    alarm[1] = 24
    }
     

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