How to know if my Character go up or go down a slope ?

Post Reply
Furya
Posts: 24
Joined: Tue Sep 22, 2015 1:34 pm

How to know if my Character go up or go down a slope ?

Post by Furya »

Hi,


My Program test if my Character is in front of a slope >60 degree. It works but I want only upward Slope !! not downward slope.
So I wonder how to know when my Character climb and not go down.

thanks
A+
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How to know if my Character go up or go down a slope ?

Post by Basroil »

If you already know the slope why not just calculate the current position vs the slope normal? Assuming X axis is forward from the facing direction to the slope, a positive rotation in the y means up slope and negative means downslope. The entire implementation would require only a few matrix multiplications at most, and very simple to figure out, if a bit unoptimized.
Furya
Posts: 24
Joined: Tue Sep 22, 2015 1:34 pm

Re: How to know if my Character go up or go down a slope ?

Post by Furya »

I tried

Code: Select all

Ogre::Quaternion q = Ogre::Vector3(point.m_positionWorldOnA).getRotationTo(Ogre::Vector3(point.m_normalWorldOnB));
			
float rotation =q.y ;
But it doesn't seem to work.
Furya
Posts: 24
Joined: Tue Sep 22, 2015 1:34 pm

Re: How to know if my Character go up or go down a slope ?

Post by Furya »

please, anyone ? :(
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: How to know if my Character go up or go down a slope ?

Post by hyyou »

If it doesn't work, is m_positionWorldOnA and m_normalWorldOnB correct?

If the problem is really come from quaternion, more information about quaternion can be found in ...
http://gamedev.stackexchange.com/questi ... quaternion
Look at the first answer and all its links. It is the best one I found so far.
Furya
Posts: 24
Joined: Tue Sep 22, 2015 1:34 pm

Re: How to know if my Character go up or go down a slope ?

Post by Furya »

I found a solution.

Code: Select all

Ogre::Vector3 dir = PJ->mNode->getOrientation() * Vector3::UNIT_Z;
			Ogre::Radian q = Ogre::Vector3(dir).angleBetween(Ogre::Vector3(point.m_normalWorldOnB));
         
			Ogre::Real rotation =q.valueDegrees()-90 ;
Post Reply