playMaker

Author Topic: (SOLVED) How to check if an object is upside down?  (Read 1983 times)

SawyerK

  • Junior Playmaker
  • **
  • Posts: 92
(SOLVED) How to check if an object is upside down?
« on: May 25, 2020, 07:41:23 AM »
Hi!
I have a rigidbody object that needs to send an event when it turns upside down.
How do i check if the object is upside down? I tried Get Rotation and Get Vector XYZ
but it doesn't seem to work with the Float Sign Test IsPositive/IsNegative event. I don't even know where to begin with this.
« Last Edit: May 29, 2020, 09:23:45 AM by SawyerK »

Athin

  • Full Member
  • ***
  • Posts: 163
Re: How to check if an object is upside down?
« Reply #1 on: May 25, 2020, 08:31:12 AM »
Heya,

Rotation would be the best bet I can think for this.  Simply just grab the rotation at the start and then check when it moves if it equals original +180 (-180 in case it goes the other way as well).

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How to check if an object is upside down?
« Reply #2 on: May 25, 2020, 10:59:29 AM »
Vectors often need to be converted to their individual floats to check them. There are actions for this, too, usually stuff like VectorXY/Z. Once you extracted the value you want to check, e.g. the rotated axis, you can check it e.g. with float compare.

SawyerK

  • Junior Playmaker
  • **
  • Posts: 92
Re: How to check if an object is upside down?
« Reply #3 on: May 26, 2020, 06:52:01 AM »
The problem is that the rotation is 0 to 360. There is no negative (-180). How do i get the negative value?

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How to check if an object is upside down?
« Reply #4 on: May 26, 2020, 03:09:50 PM »
The problem is that the rotation is 0 to 360. There is no negative (-180). How do i get the negative value?

You rotate your object in the inspector to the position that you think qualifies as “upside down”, then you note down the rotation values or range, which axis and so on. Then, put everything back how it was and use an FSM to check those conditions at runtime.

This method is generally very useful: before you implement or automate anything, test the steps “by hand”. Then you have a good idea what exactly needs to happen and it’s easier to implement.

SawyerK

  • Junior Playmaker
  • **
  • Posts: 92
Re: How to check if an object is upside down?
« Reply #5 on: May 28, 2020, 08:55:49 AM »
The floats and angles are all over the place cant use float compare with this method.

wetcircuit

  • Full Member
  • ***
  • Posts: 158
    • wetcircuit.com
Re: How to check if an object is upside down?
« Reply #6 on: May 28, 2020, 11:04:30 AM »
"The floats and angles are all over the place…"

You need an independent gameobject in your scene that is oriented 'up' as a worldspace reference to compare to.


nuFF3

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 74
  • Are we even real?
    • One Month Studio
Re: How to check if an object is upside down?
« Reply #7 on: May 28, 2020, 05:03:54 PM »
Object orientation check? Super easy.
Use 'Transform Direction', set the gameobject you want to check as the specified gameobject, and set the local direction Y to 1.
You should now get the 'normals' of the object in world space. If its upside down, the returned Y value of the 'Vector 3' variable will be -1.

SawyerK

  • Junior Playmaker
  • **
  • Posts: 92
Re: (SOLVED) How to check if an object is upside down?
« Reply #8 on: May 29, 2020, 09:23:06 AM »
WOW nuFF3 this is exactly what i needed, thank you very much! :D