playMaker

Author Topic: [SOLVED] ScreenToWorldPoint Jittering?  (Read 1948 times)

cmonroy

  • Playmaker Newbie
  • *
  • Posts: 34
    • View Profile
[SOLVED] ScreenToWorldPoint Jittering?
« on: October 16, 2014, 02:02:03 AM »
I have a simple FSM that reads the Mouse X and Y position at a determinated Z position (ten meters away from the camera). Converting that Vector3 to a point inside the game should be easy when using the ScreenToWorldPoint function, which returns a World Vector3, but for some unknown reason the Y component keeps moving randomly even when the mouse is static and basically it starts to fall down from where the mouse is pointing.

Any idea on how to solve this?

Thank you.
« Last Edit: October 16, 2014, 07:51:33 AM by cmonroy »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: ScreenToWorldPoint Jittering?
« Reply #1 on: October 16, 2014, 04:25:46 AM »
Can you show the other states? Do you have a Joystick plugged in?

You can probably actually just stack all of those three states' actions into one state if you didn't want do do the state loop like that.

cmonroy

  • Playmaker Newbie
  • *
  • Posts: 34
    • View Profile
Re: ScreenToWorldPoint Jittering?
« Reply #2 on: October 16, 2014, 07:04:36 AM »
Thank you, Lane.

No, I don't use any other input device: just the mouse and the keyboard. I usually do more things in each state, but when things produce unexpected results (as in this case) I tend to oversimplify in order to discard unnecessary clutter.

The original problem is to be able to pick up a World point using the mouse position, but I can't use Mouse Pick because there is not always some geometry to catch the raycast. As such, I use a fixed distance from the main camera to complete the Vector3 (which, by the way changes less than 1% between loops). So, since there isn't any easy way I am aware of to point-and-shoot, I am assuming that positionX and positionY in the screen, plus a fixed-distance point can help me to trace a targeting line, which can be extended to infinity if need be, will intersect my enemies regardless of their distance. When I use the ScreenToWorldPoint function to achieve this end, the input parameters are the correct X and Y coordinates of the screen, then I move a sphere to that precise World Point located 8 meters away from the main camera, but the Y component starts to change randomly and keeps going lower and lower, even if the Y screen coordinate remains at the top of the screen and the Y World component runs towards the negative realm.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: ScreenToWorldPoint Jittering?
« Reply #3 on: October 16, 2014, 07:26:58 AM »
Hmm, I just recreated this and its not drifting. Seems to work correctly. Is something else interfering with the target or tampering with the coordinates?

cmonroy

  • Playmaker Newbie
  • *
  • Posts: 34
    • View Profile
[SOLVED] ScreenToWorldPoint Jittering?
« Reply #4 on: October 16, 2014, 07:50:29 AM »
Yes... I also have a mecanim character. The jittering is produced by parenting the main camera to the character (which it was done so as to follow around the player from a fixed perspective). Seems like I'm going to have to create a new FSM to take care of the camera...

Thank you Lane.

 :)