Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

RigidBody doesn't rotate futher from 90 degrees #3

Closed
killo9ramm opened this issue Jan 24, 2020 · 2 comments
Closed

RigidBody doesn't rotate futher from 90 degrees #3

killo9ramm opened this issue Jan 24, 2020 · 2 comments

Comments

@killo9ramm
Copy link

killo9ramm commented Jan 24, 2020

Case:
1 Create new default 3D Scene
2 Take Box, create collision body in it by pressing "Add Collision" in editor
3 Place Input processing component in the box, set box as "object controlled by player"
4 Set event handler to "Input Message Event" with script

`
public void InputProcessing_InputMessageEvent(NeoAxis.Component_InputProcessing sender, NeoAxis.UIControl playScreen, NeoAxis.Component_GameMode gameMode, NeoAxis.InputMessage message)
{
var item=sender.Parent.Parent.GetComponent("Box").GetComponent("Collision Body") as Component_RigidBody;

var angleMultiplier = 5;

var keyDown = message as InputMessageKeyDown;

if(keyDown != null)
{
	if (keyDown.Key == EKeys.Up)
	{
		var angles = item.Transform.Value.Rotation.Angles;
		var position = item.Transform.Value.Position;
		var newRotation = new Angles(0, angles.Pitch + angleMultiplier , 0);
		
		Log.Info("----------");
		Log.Info(newRotation);
		
		item.SetRotation(newRotation);
	}
	
	if (keyDown.Key == EKeys.Down)
	{
		var angles = item.Transform.Value.Rotation.Angles;
		var position = item.Transform.Value.Position;
		var newRotation = new Angles(0, angles.Pitch - angleMultiplier, 0);
		
		Log.Info("----------");
		Log.Info(newRotation);
		
		item.SetRotation(newRotation);
	}
}

}
`

5 Press Play button in editor
6 Rotate Box over Y axis with Up and Down keyboard keys
7 Note that box doesn't spin futher if angle is lower than -90 or higher than 90 and start twithcing around.

@KorolevAndrey
Copy link

KorolevAndrey commented Mar 25, 2020

I confirm this problem.

But it has workaround - rotate constraint 90 deg and use different axis for spinning (z axis)

@betauser6
Copy link

Another way how to manage rotation. Use quaternion and matrix 3.

var change = Matrix3.FromRotateByY(new Degree(5));
var changeQ = change.ToQuaternion();

var original = item.Transform.Value.Rotation;
item.SetRotation(original * changeQ);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants