prevent entity from spinning
Re: prevent entity from spinning
haha yeah that worked beautifull!
It moves quite realistic, some flaws still, it can slowly run "uphill" I guess this is just lowering the maxslope right? I need to orient my model as well now. I guess raying 2 times will be the best way right? raying from the nose down and from the tail down, those 2 hitlocations will be the orientation (if I would do this after the y rotation, this will result me only the correct x/z axis rotations) or is there a quicker way? just the straight normal of the current location?
It moves quite realistic, some flaws still, it can slowly run "uphill" I guess this is just lowering the maxslope right? I need to orient my model as well now. I guess raying 2 times will be the best way right? raying from the nose down and from the tail down, those 2 hitlocations will be the orientation (if I would do this after the y rotation, this will result me only the correct x/z axis rotations) or is there a quicker way? just the straight normal of the current location?
Re: prevent entity from spinning
It should be able to slide uphill some if you build up the momentum; if you mean being able to go uphill from dead stop, then you might need to still set the acceleration to zero.it can slowly run "uphill" I guess this is just lowering the maxslope right?
"maxSlope" is the slope at which the character loses the ability to control itself (hasTraction = false) and begins to slide using its slidingDeceleration instead of tractionDeceleration. This might be useful for some effects (tumbling wildly down a cliff face with no control). You might actually find that increasing it some (pi/3?) feels better when you're doing a daring 60-degree-slope-almost-freefall maneuver.
The character computes the support normal during normal processing in its UpdateAtEndOfUpdate method. You could store that into a public field and access it to help orient your graphics. This would probably be the best/easiest starting point for computing the slope component of the orientation.is there a quicker way? just the straight normal of the current location?
Re: prevent entity from spinning
yeah, it kind of slowly walks uphill from a dead stop. But this is not really a bad thing I figured. I will just make a "walk" animation, when the speed is below say 2 m/s the walk animation will be triggered (so the person can't get stuck at a certain point, since he always can walk out of it) but I'm not sure, the acceleration to zero is probably nicer to start with.
All units are SI units right? Meters, seconds, m/s etc?
I probably need 2 normals, one of the nose and one where the tail touches, otherwise the board will go "trough" the hill on steep slopes, since it only computes the normal underneath the center. But this won't be hard to fix, I just have to add 2 raytraces from bodycenterposition + vector3(0, -1, -/+1.5f)*orientationbody and that should do the trick to provide the positions. the orientation is then just the diffrencevector between 1 and 2.
All in all really nice so far, the control is good. I am working on the camera movements now, its looking good so far. The trick part will be kind of tricky
I think I will have to rotate the model according to the character collision boxes (I check whenever the model is "off the ground", and then the player can rotate the model freely, If the model will hit the ground while the orientation is more off from the normal than say 30 degrees). This will be a little problematic still to finetune it all I think. But so far it's all much cleaner than the vehicle class. and is easy to control which is exactly what we want.
Thanks for all the help so far!
All units are SI units right? Meters, seconds, m/s etc?
I probably need 2 normals, one of the nose and one where the tail touches, otherwise the board will go "trough" the hill on steep slopes, since it only computes the normal underneath the center. But this won't be hard to fix, I just have to add 2 raytraces from bodycenterposition + vector3(0, -1, -/+1.5f)*orientationbody and that should do the trick to provide the positions. the orientation is then just the diffrencevector between 1 and 2.
All in all really nice so far, the control is good. I am working on the camera movements now, its looking good so far. The trick part will be kind of tricky

Thanks for all the help so far!
Re: prevent entity from spinning
The engine itself is unitless; you can consider the units to be SI if you are consistent with their usage. So if gravity is -9.81 and you have humanoid people that are a little under 2 units tall, then your length unit can be considered a meter. Sometimes, deviating from SI for the sake of numerical issues or convenience is a good idea. You don't have to use kilograms for mass if you don't want to, for example. The engine doesn't care either way.All units are SI units right? Meters, seconds, m/s etc?
The only time it would go through with a single central raycast is when the terrain is locally concave. On a simple flat steep slope, it would look fine. Creating a situation where it was noticeably bad would also be very hard to slide over anyway. For two raycasts at the ends of the board, you have the opposite problem- the detection would do something weird when you're at the top of a bump. Snow is soft, too; you can use that as an excuse when the board gets temporarily hidden (like it does constantly in those game videos)I probably need 2 normals, one of the nose and one where the tail touches, otherwise the board will go "trough" the hill on steep slopes

Re: prevent entity from spinning
Oké i,m trying to clean up my code a bit.
I got THE normal, i coverted this to angles by this code
Vector3.Normalize(normalVector);
xRotation = Math.Acos(normalVector.X);
yRotation = Math.Acos(normalVector.Y);
zRotation = Math.Acos(normalVector.Z);
GraphicOrient = Matrix.CreateFromYawPitchRoll(xRotation, yRotation + MathHelper.PiOver2, xRotation);
OrientMatrix = Matrix.CreateRotationZ(flipAngle) * Matrix.CreateRotationY(spinAngle) * GraphicOrient;
How do i align my graphic according to this? I gues i just have to rotate the collision object only in the y direction so it Will always be upright. and use these roations to compensate graphically for the bumps, and make ANOTHER orientation matrix for the external rotations for tricks etc, am i right?
I was kind of struggeling with this since i did not know wheter the angles where right, since the normal is not the orientation of the board. And preferebly the graphics for bumps get only compensated in its internal z direction (Front/back). Thanks! Flipangle would be the back,frontflip rotations angle and spin the screw spin Axel, so a fulltime circle Will be à 360 just like skateboarding etc.
I like to work witheet angles since this is easier for me to determine when à trick has been landed succesfully and to visualise the amount of rotations better than in à vector or matrix
Thanks!
I got THE normal, i coverted this to angles by this code
Vector3.Normalize(normalVector);
xRotation = Math.Acos(normalVector.X);
yRotation = Math.Acos(normalVector.Y);
zRotation = Math.Acos(normalVector.Z);
GraphicOrient = Matrix.CreateFromYawPitchRoll(xRotation, yRotation + MathHelper.PiOver2, xRotation);
OrientMatrix = Matrix.CreateRotationZ(flipAngle) * Matrix.CreateRotationY(spinAngle) * GraphicOrient;
How do i align my graphic according to this? I gues i just have to rotate the collision object only in the y direction so it Will always be upright. and use these roations to compensate graphically for the bumps, and make ANOTHER orientation matrix for the external rotations for tricks etc, am i right?
I was kind of struggeling with this since i did not know wheter the angles where right, since the normal is not the orientation of the board. And preferebly the graphics for bumps get only compensated in its internal z direction (Front/back). Thanks! Flipangle would be the back,frontflip rotations angle and spin the screw spin Axel, so a fulltime circle Will be à 360 just like skateboarding etc.
I like to work witheet angles since this is easier for me to determine when à trick has been landed succesfully and to visualise the amount of rotations better than in à vector or matrix
Thanks!
Re: prevent entity from spinning
Unfortunately, you're going to see a lot of Matrix and Vector stuff when dealing with orientations and transformations just because it's far easier to correctly compute things in such a form. The 'three angle' orientation representation is limited and will almost always cause some annoying problem.
Here's the general way I would approach computing a matrix that fits something to a normal:
If you want the board to tip forward and back only, then you need to compute the angle to rotate around the character's 'sideways' axis. This is similar to how you'd calculate an angle on a traditional 2d graph, using the Math.Atan2 function. The problem is, what are x and y? We need an X and Y axis to 'measure' the normal against to find out. Fortunately, we know two axes that are perpendicular to the sideways axis- the movement direction, and the up vector. We can dot against those axes to get the x and y component, plug them into the Atan2, and get the angle.
But what is the sideways axis that is being rotated around? We can get it directly from the movement direction, rotated by 90 degrees. For our movement direction (x, z), the sideways axis is (z, 0, -x). Try drawing the points on a graph and rotating it to visualize why this is, or use the fact that the dot product between the two (2d) vectors is 0, meaning they are perpendicular.
So the code would look something like this:
The actual entity body of the character should never rotate during any maneuvers (it's possible to do, but you need to be prepared to deal with the consequences), so any rotation will be graphical/gameplay logic, not direct physical dynamics.
To do tricks, you could manage some sort of 'gameplay orientation' matrix or quaternion. One way to rotate it would be to use angular velocities, where the magnitude of angular velocity is the radians per second, and the normalized direction of the angular velocity is the spin axis. Each frame, you could increment the rotation using the velocity (a simple axis angle matrix multiplication for orientation matrices).
In addition, you can measure the total rotation like I mentioned in an earlier post by summing up the velocity * dt. Summing up individual velocity magnitude * dt gives you the total rotation, but you could also sum parts of the angular velocity. For example, by dotting the angular velocity with the world up vector and multiplying by dt, you get a frame's rotation around the up axis. You could also do it in the gameplay orientation's 'local space,' using the gameplay orientation's own up vector instead. The same idea would work for the other axes as well.
To see if a character successfully lands after being airborne, check the tilt angle as shown earlier. If your 'gameplay' orientation compared with the normal shows a small tilt, then you can land. If not, you wipe out.
Be aware that I wrote all of the above in notepad, so I don't guarantee that everything is error free
This might be a lot to digest, but efficiently dealing with matrices/vectors and linear algebra in general is extremely valuable. There's a lot of information out there about it; here's a fairly recent relevant link: http://stevehazen.wordpress.com/2010/02 ... -3-angles/
Here's the general way I would approach computing a matrix that fits something to a normal:
Code: Select all
Matrix alignToSurface;
float tiltAngle = (float)Math.Acos(normal.Y); //This is equivalent to arccos(normal dot upvector), since the up vector is (0,1,0)
if(tiltAngle > SomeSmallValue) //Don't want to normalize something that results in almost dividing by zero
{
Vector3 tiltAxis = Vector3.Normalize(Vector3.Cross(normal, Vector3.Up)); //This could also be 'simplified' since the up vector is (0,1,0), but it would take more work :)
alignToSurface = Matrix.CreateFromAxisAngle(tiltAxis, tiltAngle);
}
else
alignToSurface = Matrix.Identity;
But what is the sideways axis that is being rotated around? We can get it directly from the movement direction, rotated by 90 degrees. For our movement direction (x, z), the sideways axis is (z, 0, -x). Try drawing the points on a graph and rotating it to visualize why this is, or use the fact that the dot product between the two (2d) vectors is 0, meaning they are perpendicular.
So the code would look something like this:
Code: Select all
Vector3 movementDirection3D = new Vector3(movementDirection.X, 0, movementDirection.Y);
float x = Vector3.Dot(movementDirection3D, normal);
float y = normal.Y; //Again, Vector3.Dot(normal, Vector3.up) is equivalent to just normal.Y
float pitchAngle = (float)Math.Atan2(y, x);
Vector3 sidewaysDirection = new Vector3(movementDirection.Y, 0, -movementDirection.X);
Matrix alignToSurface = Matrix.CreateFromAxisAngle(sidewaysDirection, pitchAngle);
To do tricks, you could manage some sort of 'gameplay orientation' matrix or quaternion. One way to rotate it would be to use angular velocities, where the magnitude of angular velocity is the radians per second, and the normalized direction of the angular velocity is the spin axis. Each frame, you could increment the rotation using the velocity (a simple axis angle matrix multiplication for orientation matrices).
In addition, you can measure the total rotation like I mentioned in an earlier post by summing up the velocity * dt. Summing up individual velocity magnitude * dt gives you the total rotation, but you could also sum parts of the angular velocity. For example, by dotting the angular velocity with the world up vector and multiplying by dt, you get a frame's rotation around the up axis. You could also do it in the gameplay orientation's 'local space,' using the gameplay orientation's own up vector instead. The same idea would work for the other axes as well.
To see if a character successfully lands after being airborne, check the tilt angle as shown earlier. If your 'gameplay' orientation compared with the normal shows a small tilt, then you can land. If not, you wipe out.
Be aware that I wrote all of the above in notepad, so I don't guarantee that everything is error free

This might be a lot to digest, but efficiently dealing with matrices/vectors and linear algebra in general is extremely valuable. There's a lot of information out there about it; here's a fairly recent relevant link: http://stevehazen.wordpress.com/2010/02 ... -3-angles/
Re: prevent entity from spinning
Thanks however the first code displays the graphics upside down 
when I do
it's orientation is perfect. Really odd, I had the upside down problem with the angles as well, guess has to do something with the normal itself it's always around -0.9 or so in the y directions, so actually the normal is aimed to the surface instead of out of the surface or the raying happens from underneath. If I'm correct.
The second code is in the opposite y rotation as well and the image is rotated 90 degrees. I'm trying to see where the problem is. thanks for the code so far. Indeed it only rotates in the right axis, but direction etc is off.

when I do
Code: Select all
float tiltAngle = (float)Math.Acos(-SnowBoardingGame.orientationTransform.Y); //This is equivalent to arccos(normal dot upvector), since the up vector is (0,1,0)
if (tiltAngle > 0.00001f) //Don't want to normalize something that results in almost dividing by zero
{
Vector3 tiltAxis = Vector3.Normalize(Vector3.Cross(SnowBoardingGame.orientationTransform, Vector3.Up)); //This could also be 'simplified' since the up vector is (0,1,0), but it would take more work :)
SnowBoardingGame.alignToSurface = Matrix.CreateFromAxisAngle(tiltAxis, tiltAngle);
}
else
SnowBoardingGame.alignToSurface = Matrix.Identity;
The second code is in the opposite y rotation as well and the image is rotated 90 degrees. I'm trying to see where the problem is. thanks for the code so far. Indeed it only rotates in the right axis, but direction etc is off.
Re: prevent entity from spinning
Code: Select all
Vector2 totalMovement = Vector2.Zero;
//Collect the movement impulses.
Vector3 movementDir;
acc += dt;
float turnSpeed = 2.5f + 0.5f * 25 * acc * acc; // degrees per update
// Cap turnspeed;
if (SnowBoardingGame.onTheGround == false)
{
if (turnSpeed > 12.5f) turnSpeed = 12.5f;
} else {
if (turnSpeed > 7.5f) turnSpeed = 7.5f;
}
if (SnowBoardingGame.onTheGround == false)
{
if (SnowBoardingGame.joyStickLeftAction.Contains("North"))
{
SnowBoardingGame.trickRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Left, turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction.Contains("South"))
{
SnowBoardingGame.trickRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Left, -turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction.Contains("West"))
{
SnowBoardingGame.trickRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Up, turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction.Contains("East"))
{
SnowBoardingGame.trickRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Up, -turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction == "")
{
acc = 0;
}
}
else
{
if (SnowBoardingGame.joyStickLeftAction.Contains("West"))
{
SnowBoardingGame.groundRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Up, turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction.Contains("East"))
{
SnowBoardingGame.groundRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Up, -turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction == "")
{
acc = 0;
}
SnowBoardingGame.trickRotationMatrix = SnowBoardingGame.groundRotationMatrix;
}
movementDir = SnowBoardingGame.groundRotationMatrix.Forward;
totalMovement += Vector2.Normalize(new Vector2(movementDir.X, movementDir.Z));
// Orienting the graphics when on the ground.
Vector3 movementDirection3D = new Vector3(movementDir.X, 0, movementDir.Z);
float x = -Vector3.Dot(movementDirection3D, SnowBoardingGame.orientationTransform);
float y = SnowBoardingGame.orientationTransform.Y; //Again, Vector3.Dot(normal, Vector3.up) is equivalent to just normal.Y
pitchAngle = ((float)Math.Atan2(y, x) + MathHelper.PiOver2);
SnowBoardingGame.alignToSurface = Matrix.CreateFromAxisAngle(SnowBoardingGame.groundRotationMatrix.Left, pitchAngle);
Do you know if there is a smartway to "round" the angles so when landing it should be possible to ride backwards so it should round it to 180 degrees, like with angles you would do this RoundedAngle = Round(Angle/step)* step (where step is 180 degrees for half circle rounded, 360 for full circle).
thanks! i'm excited although is should study now haha, too distracting.
Last edited by Marvin on Wed Aug 25, 2010 1:31 pm, edited 1 time in total.
Re: prevent entity from spinning
To simplify things, I would avoid maintaining two conceptual matrices. Whenever it's on the ground, it simply uses the (align to movement direction yaw) * (align to surface) matrix. When it leaves the ground, it continues with the same transformation, which is incrementally updated with trick-velocity until it lands.
However, there are some significant issues that need to be dealt with before going further. I haven't looked at the posted code in depth, but here's a few issues:
-The character controller's orientation matrix is modified. It only is rotated around the Y axis, so it has essentially no collision effect, but it should not be modified in the first place. It's possible to make a system in which the character's orientation changes, but you have to deal with a lot more problems, so I just suggest avoiding it entirely for simplicity and clarity.
-The character controller's orientation matrix is used to define the movement direction. Obviously, to go along with the above suggestion, this should be avoided.
-'totalMovement' isn't used. 'movementDirection' is created from the character's up vector (which should be the same as Vector3.Up, to go along with the first suggestion).
-The movementDirection3D does not correspond to the movement direction, but rather Vector3.Forward, always.
-The way the alignToSurface matrix is computed has been changed fairly randomly and probably doesn't do what you want it to do. While I may have made an error in the original (I have not tested it), make sure you understand why you made each change. Trial and error almost never actually works, even if it looks like it does for one or two tests
However, there are some significant issues that need to be dealt with before going further. I haven't looked at the posted code in depth, but here's a few issues:
-The character controller's orientation matrix is modified. It only is rotated around the Y axis, so it has essentially no collision effect, but it should not be modified in the first place. It's possible to make a system in which the character's orientation changes, but you have to deal with a lot more problems, so I just suggest avoiding it entirely for simplicity and clarity.
-The character controller's orientation matrix is used to define the movement direction. Obviously, to go along with the above suggestion, this should be avoided.
-'totalMovement' isn't used. 'movementDirection' is created from the character's up vector (which should be the same as Vector3.Up, to go along with the first suggestion).
-The movementDirection3D does not correspond to the movement direction, but rather Vector3.Forward, always.
-The way the alignToSurface matrix is computed has been changed fairly randomly and probably doesn't do what you want it to do. While I may have made an error in the original (I have not tested it), make sure you understand why you made each change. Trial and error almost never actually works, even if it looks like it does for one or two tests

Re: prevent entity from spinning
thanks, I can work with that.
Forgot that part of code. it is infact in use. when on the ground else it will just keep flying in the same direction, since steering in the air is not possibble, this works fine.
Now I modified it a bit, so I have an orientation matrix for on the ground and a trickmatrix.
It was not just totally random, the orientation is mirrored over the x-asix, so when the board should go up on it's z-axis it's going downwards and when it should go down it goes up.
It works now, i just had to do the following:
EDIT: Ow bummer, it does not work when the person is going sideways (it will still correct in the z direction only, while is should be correction only in the x direction then! so it should be CorrectionVector = new Vector3(cos(angle)*correctionValue, 0, sin(angle)*correctionValue) or something like that
I still have to build the switch landing and such, because right now it sets the player back to its original orientation. I still have to compute when the players is landing backwards.
is there a nice way to "round" the rotations on half and full circles? in matrices, just like with angles one would do, Math.Round(angle / step) * step with step = 180 degrees for half circle round, 360 for full circle round.
Code: Select all
if (SnowBoardingGame.onTheGround == true)
{
characterController.movementDirection = Vector2.Normalize(totalMovement);
}
Now I modified it a bit, so I have an orientation matrix for on the ground and a trickmatrix.
It was not just totally random, the orientation is mirrored over the x-asix, so when the board should go up on it's z-axis it's going downwards and when it should go down it goes up.
It works now, i just had to do the following:
in snowboarding game://Collect the movement impulses.
Vector3 movementDir;
acc += dt;
float turnSpeed = 2.5f + 0.5f * 25 * acc * acc; // degrees per update
// Cap turnspeed;
if (SnowBoardingGame.onTheGround == false)
{
if (turnSpeed > 12.5f) turnSpeed = 12.5f;
} else {
if (turnSpeed > 7.5f) turnSpeed = 7.5f;
}
if (SnowBoardingGame.onTheGround == false)
{
if (SnowBoardingGame.joyStickLeftAction.Contains("North"))
{
SnowBoardingGame.trickRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Left, turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction.Contains("South"))
{
SnowBoardingGame.trickRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Left, -turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction.Contains("West"))
{
SnowBoardingGame.trickRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Up, turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction.Contains("East"))
{
SnowBoardingGame.trickRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.trickRotationMatrix.Up, -turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction == "")
{
acc = 0;
}
}
else
{
if (SnowBoardingGame.joyStickLeftAction.Contains("West"))
{
SnowBoardingGame.groundRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.groundRotationMatrix.Up, turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction.Contains("East"))
{
SnowBoardingGame.groundRotationMatrix *= Matrix.CreateFromAxisAngle(SnowBoardingGame.groundRotationMatrix.Up, -turnSpeed * 0.01f);
}
if (SnowBoardingGame.joyStickLeftAction == "")
{
acc = 0;
}
SnowBoardingGame.trickRotationMatrix = SnowBoardingGame.groundRotationMatrix;
}
movementDir = SnowBoardingGame.groundRotationMatrix.Forward;
totalMovement += Vector2.Normalize(new Vector2(movementDir.X, movementDir.Z));
// Orienting the graphics when on the ground.
Vector3 movementDirection = SnowBoardingGame.groundRotationMatrix.Up;
Vector3 movementDirection3D = new Vector3(movementDirection.X, 0, movementDirection.Y);
float x = -Vector3.Dot(movementDirection3D, SnowBoardingGame.orientationTransform);
float y = SnowBoardingGame.orientationTransform.Y; //Again, Vector3.Dot(normal, Vector3.up) is equivalent to just normal.Y
float pitchAngle = (float)Math.Atan2(y, x);
Vector3 sidewaysDirection = new Vector3(movementDirection.Y, 0, -movementDirection.X);
SnowBoardingGame.alignToSurface = Matrix.CreateFromAxisAngle(sidewaysDirection, pitchAngle);
//Jumping
/*
if (previousKeyboardInput.IsKeyUp(Keys.A) && keyboardInput.IsKeyDown(Keys.A))
{
characterController.jump();
}
*/
if (SnowBoardingGame.onTheGround == true)
{
characterController.movementDirection = Vector2.Normalize(totalMovement);
}
It's not the nicest code, but hey it works fine. the orrientation is correct etc.characterPosition = character.characterController.position;
wobbleCorrection = Matrix.CreateRotationX(MathHelper.PiOver2) * alignToSurface;
worldTransform = trickRotationMatrix * wobbleCorrection * Matrix.CreateTranslation(character.characterController.position);
EDIT: Ow bummer, it does not work when the person is going sideways (it will still correct in the z direction only, while is should be correction only in the x direction then! so it should be CorrectionVector = new Vector3(cos(angle)*correctionValue, 0, sin(angle)*correctionValue) or something like that
I still have to build the switch landing and such, because right now it sets the player back to its original orientation. I still have to compute when the players is landing backwards.
is there a nice way to "round" the rotations on half and full circles? in matrices, just like with angles one would do, Math.Round(angle / step) * step with step = 180 degrees for half circle round, 360 for full circle round.
Re: prevent entity from spinning
It comes down to just transforming the matrix in some way to accomplish what you want. I'll leave this one as an exercise for the readerDo you know if there is a smartway to "round" the angles so when landing it should be possible to ride backwards so it should round it to 180 degrees, like with angles you would do this RoundedAngle = Round(Angle/step)* step (where step is 180 degrees for half circle rounded, 360 for full circle).

Think about exactly what change needs to occur. What is the current state, and what is the desired state? What transformation will get you from the current state to the desired state?
Re: prevent entity from spinning
Well what my code right now does is it has 2 matrices for transformation and orientation. On startup both will be exactly the same, and while it's on the ground one matrix gets reorientated when steering, this matrix is then again copied to the other matrix. The second matrix gets reorientated seperately from the groundorientationmatrix only when in the air. Whenever it lands the trickorientationmatrix will be the copied version of the ground orientation (which in this case is the perfect landing!). This works, however one can land perfect "switch" as well, so I somehow have to figure out the y rotation and have not been succesfull with it.
I created a simple boolean which captures the last airOrientation matrix before landing. I can compare this with the groundOrientation matrix and then determine wheter the player should fall down. This is not that big of a deal. But I actually want to orientate the board backwards if the player lands backwards, so kind of Invertring the y direction whenever a player lands switch. I should check in the up vector of both the groundMatrix and the Orientation matrix and spot if the plus is a minus and vica versa in one matrix comapred to the other as the Z value right?
I created a simple boolean which captures the last airOrientation matrix before landing. I can compare this with the groundOrientation matrix and then determine wheter the player should fall down. This is not that big of a deal. But I actually want to orientate the board backwards if the player lands backwards, so kind of Invertring the y direction whenever a player lands switch. I should check in the up vector of both the groundMatrix and the Orientation matrix and spot if the plus is a minus and vica versa in one matrix comapred to the other as the Z value right?
Re: prevent entity from spinning
After you determine that it can land (in whatever way you'd like to do that), assuming the forward vector of the air orientation matrix represents the actual facing direction, you can compute the new movement direction directly from it. Here's one way to do it:
movementDirection = Vector2.Normalize(new Vector2(airOrientation.Forward.X, airOrientation.Forward.Z);
As long as you verify beforehand that the character is in a good landing state (not upside down), the movement direction would have some useful meaning.
This would let you land and face whatever direction was reasonably close to what direction you were facing while flying through the air, rather than arbitrarily pointing straight forward or back.
movementDirection = Vector2.Normalize(new Vector2(airOrientation.Forward.X, airOrientation.Forward.Z);
As long as you verify beforehand that the character is in a good landing state (not upside down), the movement direction would have some useful meaning.
This would let you land and face whatever direction was reasonably close to what direction you were facing while flying through the air, rather than arbitrarily pointing straight forward or back.
Re: prevent entity from spinning
ah yeah thats a good solution as well.
I figured something different out in the mean while. The rotation speed is angular speed so I just summed all the rotations around the vertical axis. once this is like 180 + n*360 it will just round it to 180 degrees and add it to the standard orientation of before takeoff, this works correct as well.
Now the hard part, the combination of rotations barrell rolls front flips etc. is quite tricky to sum it all correctly
. But it seems to work now. Still a slightproblem with the frontflip plus backflip combination which will be no flip at all now. So I have to make a counter to count each flip
I figured something different out in the mean while. The rotation speed is angular speed so I just summed all the rotations around the vertical axis. once this is like 180 + n*360 it will just round it to 180 degrees and add it to the standard orientation of before takeoff, this works correct as well.
Now the hard part, the combination of rotations barrell rolls front flips etc. is quite tricky to sum it all correctly

Re: prevent entity from spinning
Okey I'm working on the landing part now. It's kind of tricky.
Say I got the ground normal, and I got the orientation matrix of the trick in the air. How am I able to compare those angles? Again the only angles that matter for the landing is the rotation around the internal x-axis. this should be roughly between -30 and plus 15 degrees. I already got the sideways rotation, so I can just check when this rotation is appropriate for a good landing. But the forward and backwards rotation )frontflip/backflip) should also take the angle of the terrain into consideration (f/e a further rotation forwards when the landing is steep and a practically horizontal landing on a horizontal surface).
Any suggestions how to get this done? so when I got the terrain normal, then figuring out the steepness of the hill in the travel direction of the character then taking the flip angle into account?
thank you very much!
Say I got the ground normal, and I got the orientation matrix of the trick in the air. How am I able to compare those angles? Again the only angles that matter for the landing is the rotation around the internal x-axis. this should be roughly between -30 and plus 15 degrees. I already got the sideways rotation, so I can just check when this rotation is appropriate for a good landing. But the forward and backwards rotation )frontflip/backflip) should also take the angle of the terrain into consideration (f/e a further rotation forwards when the landing is steep and a practically horizontal landing on a horizontal surface).
Any suggestions how to get this done? so when I got the terrain normal, then figuring out the steepness of the hill in the travel direction of the character then taking the flip angle into account?
thank you very much!