Why is this value becoming NaN?

0 favourites
  • 6 posts
  • The position turns out as NaN for seemingly no reason...

    When I set the position to cos(90), that works fine, but cos(ang) just doesn't work.

    'ang' is just a number, so what's going on?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well... NaN stands for Not a Number. So it's not a number.

    You usually get this value when performing operations that result in an indefinite result, like for instance, dividing by 0. There are many more possibilities though.

    Have you checked the value of ang in the profiler? Have you checked the value of the image points?

  • that's the thing... 'ang' just appears to be a normal number - an angle from -180 to 180, depending on the mouse. It's a valid number, according to debug mode.

    (I'm starting to think this might be a construct bug, or something I don't understand about runtime)

  • Does that image point exist? If it's an animation maybe it doesn't exist on all the frames. Or it might just be the wrong name, wrong casing maybe?

  • It should work even if the image point doesn't exist.

    The formula for cursor is a bit wrong, it should be (playerHead.imagePointX("eye")+radius*cos(ang) , playerHead.imagePointY("eye")+radius*sin(ang))

    Although this still doesn't explain why the result is NaN. Maybe there are some other events which can change cursor position?

  • The image point does exist. I believe it's a construct bug, as I managed to fix this bug by making a new sprite object, and setting the angle of that instead of using a local variable. There are no other events affecting the mouse position.

    (The radius is 1 in my case, so my formula is correct)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)