Jump to content


Photo

Speed=0 but object still moving?


  • Please log in to reply
6 replies to this topic

#1 Metalmurphy

Metalmurphy

    GMC Member

  • New Member
  • 9 posts
  • Version:GM:Studio

Posted 11 August 2012 - 12:24 AM

I'm trying to make an object move to a certain destination and slowly come to a stop as it's reaching it. I was messing around with a code like this

if (go_left = 1) {
if x<new_location-(new_location*0.2)
speed=5;
if x<new_location-(new_location*0.1)
speed=1;
}

if x==new_location {
go_left=0;
go_right=0;
speed=0;
}

And something odd happened, the object would slow down but then when speed reached 0 (and it did according to the debug watcher) the object would not stop, it kept going at what seemed to be a speed of 1.

Any idea why this is happening?
  • 0

#2 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 12:33 AM

The speed didn't actually hit zero it was so close to zero that it was rounded. You should probably have
If (x<=newlocation&&go_left=1)||(x>=newlocation&&go_right=1)
For your second if, that way if you miss it by .00000001 it doesnt matter.
  • 0

#3 Metalmurphy

Metalmurphy

    GMC Member

  • New Member
  • 9 posts
  • Version:GM:Studio

Posted 11 August 2012 - 12:36 AM

But I'm manually setting the speed to 0 when it reaches the destination, why would it round something different?


if x==new_location {
go_left=0;
go_right=0;
speed=0;
}

and this part isn't inside other ifs, I basically want it to stop no matter what if it's position is the same as new_destination.

Edited by Metalmurphy, 11 August 2012 - 12:37 AM.

  • 0

#4 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 12:40 AM

It did not reach its destination... Your code had its speed at .000001 and its location .0000001 pixels away from the destination... You should always plan for variables to go past the destination a little even if they logically won't, but in this case it logically would.
Your 2nd part ofthe code was never beig called bro

Edited by youngjake, 11 August 2012 - 12:41 AM.

  • 0

#5 Metalmurphy

Metalmurphy

    GMC Member

  • New Member
  • 9 posts
  • Version:GM:Studio

Posted 11 August 2012 - 12:45 AM

I see what your saying now, but how come the speed changed in the debug watcher from 1 to 0? It should be either one or the other, since that's the only changes i make, and not something in between.


Or is the transition gradual when you change the speed variable manually?

Edited by Metalmurphy, 11 August 2012 - 12:46 AM.

  • 0

#6 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 01:03 AM

Oh I read something wrong.. I take it back the speed close to zero thing, the debug thing must have been wrong or something, but if you switch it to what I said it will work. Cant explain that debug watcher thing, no idea
  • 0

#7 Metalmurphy

Metalmurphy

    GMC Member

  • New Member
  • 9 posts
  • Version:GM:Studio

Posted 11 August 2012 - 01:05 AM

Yes it did work. Many thanks. :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users