1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

What is wrong with this code?

Discussion in 'Programming' started by veko, Jan 28, 2017.

Tags:
  1. veko

    veko Guest

    I have this simple accelleration code on my obj enemy.
    He is suppossed to dash towards player and the slow down.
    In my create event it sets 1 to alarm[0] and in alarm[0] it sets direction towards player and speed on 50 and resets it self to 500.
    And this is what i have on step event for slowing down:
    if speed = 50
    {
    for (i = 0; i < 20; i += 1)
    {
    speed -= 2.5;
    }
    }
    It seems that this code is not working since it follows the player on speed 50 forever.
    If somebody could help me out that would be great. Thank you!
     
  2. trebor777

    trebor777 Member

    Joined:
    Dec 19, 2016
    Posts:
    19
  3. veko

    veko Guest

    But what?! Im sorry but i actually never had such a simple problem that i couldn't solve! I tried to go through the link you gave me but it seems that everything is in order.
    Please help me :(
    I tried doing this but it doesn't change anything!
    Code:
    if speed == 50
    {
    for (var i = 0; i < 20; i++;)
    {
    speed -= 2.5;
    }
    }
     
  4. Sabnock

    Sabnock Member

    Joined:
    Jul 21, 2016
    Posts:
    311
    Take a look at the first line of code
     
  5. Sabnock

    Sabnock Member

    Joined:
    Jul 21, 2016
    Posts:
    311
    Also you are using a for to loop in the step so all you would see is the object stop not slow down over time.
     
  6. Joe Ellis

    Joe Ellis Member

    Joined:
    Aug 30, 2016
    Posts:
    994
    asking if its equal to 50 will only make the below code happen when its exactly 50, which it will only be for 1 frame then gradually reduce, so you need to ask if its more than 0, cus anything above 0 is still moving, also "for" loops are for making things happen more than once per frame, you need the object to only reduce speed once per frame, as you only see 1 frame at a time, so anything that happens in between frames will all join together and be displayed in the next frame
     
  7. Salvakiya

    Salvakiya Member

    Joined:
    Jul 17, 2016
    Posts:
    84
    may or may not help... depends on your code... but look up friction in the help docs.

    if speed>10{friction =.5}else{friction=.1}
     

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