3rd person camera camera orbit problem


I created this logic node for camera orbit.
The problem comes when i rotate over 1.52 radiants on the left or otherwise -1.52 radiants on the right, the camera start to go upside-down and can’t complete the rotation around the player

Here is the flipped one:-

It is easy and accurate to rotate on one axis. However, it is difficult to rotate with two axes.

1 Like

Try doing something like this in nodes:
https://blackgoku36.github.io/armory-tutorials/#/docs/Game_Demo/City_Sim/Basics?id=arcball-camera
(An empty is parented to camera, and this empty is at center)

if(mouse.down("right")){
     // Rotate our empty on z-axis in opposite direction of our mouse-x movement.
     // Mouse movement is divided by 200 to slow the rotation.
     cameraEmpty.rotate(new Vec4(0, 0, 1), -mouse.movementX / 200);
     cameraEmpty.buildMatrix();
     cameraEmpty.rotate(object.transform.world.right(), -mouse.movementY / 200);
     cameraEmpty.buildMatrix();
}
2 Likes

I have applied for additional nodes to implement the code written by @BlackGoku36.
1

The blue node is the node under application.

3 Likes

@Sandy Cool, is there a difference from your node compared to a setup using “Get Transform” -> “Vector form Transform” ? Would be handy to be able to use your single node instead.

1 Like

I solved using two Haxe Script one for the Camera Pivot:-

package arm;
import iron.object.Object;
import iron.math.Vec3;
import iron.math.Quat;
import iron.system.Input;

class CameraControl extends iron.Trait {

public var vec=new Vec3(0,0,0);

public function new() {
	super();

	 notifyOnInit(function() {
		
		// get the CameraPivot rotation in EulerAngles
		vec.x=object.transform.rot.getEuler().x;
		vec.y=object.transform.rot.getEuler().y;
		vec.z=object.transform.rot.getEuler().z;
	 });

	notifyOnUpdate(function() {
		
		// get the Gamepad
		var gamepad=iron.system.Input.getGamepad(0);
		
		// get the Gamepad Axis
		var rightstickXAxis  = gamepad.rightStick.x;
		var rightstickYAxis  = gamepad.rightStick.y;
					
		
		// increment 
		vec.x+=rightstickYAxis*0.01;
		vec.z+=rightstickXAxis*0.01;
		
		
		
		object.transform.rot.fromEuler(vec.x, vec.y, vec.z);
		object.transform.buildMatrix();


	});

	// notifyOnRemove(function() {
	// });
}

}

And one for the Player:-

package arm;
import iron.system.Input;
import iron.math.Vec2;
import iron.object.Object;
class MovementByCode extends iron.Trait {

// ottengo il gamepad
public var gamePad=iron.system.Input.getGamepad(0);
private var coords = new Vec2(0,0);

private var direction:Float;
	
@prop
private var pivot:Object;

private function AggiornaRotazione(angolo:Float){
	     
		 object.transform.rot.fromEuler(0, 0, pivot.getTrait(CameraControl).vec.z+angolo);
		 object.transform.buildMatrix();
		 
	 }

public function new() {
	super();

	// inizializzazione

	notifyOnInit(function() {
	  
	 });

	// update function
	notifyOnUpdate(function() {
		// ottengo le coordinate di input del Gamepad
		coords.x = gamePad.leftStick.x;
		coords.y = gamePad.leftStick.y;
		
		if(coords.y>0.2 && (coords.x>-0.2 && coords.x< 0.2))					
				AggiornaRotazione(0);
		else if(coords.x>0.2 && coords.y>0.2)
			    AggiornaRotazione(-0.785);
		else if(coords.x>0.2 && coords.y<-0.2)
		        AggiornaRotazione(3.925);
        else if(coords.x<-0.2 && coords.y>0.2)
		  	    AggiornaRotazione(0.785);
		else if(coords.x<-0.2 && coords.y<-0.2)
		        AggiornaRotazione(2.355);
		else if(coords.x>0.2 && (coords.y>-0.2 && coords.y< 0.2))
			    AggiornaRotazione(-1.57);
        else if(coords.x<-0.2 && (coords.y>-0.2 && coords.y< 0.2))
		        AggiornaRotazione(1.57);
        else if(coords.y<-0.2 && (coords.x>-0.2 && coords.x< 0.2))
		        AggiornaRotazione(3.14);
	 });
	 

	// notifyOnRemove(function() {
	// });
}

}

Both setup are same, The only difference is that @Sandy’s node doesn’t have quaternion.

3 Likes

Thank you for pointing out @Simonrazer. As @BlackGoku36 says.

1 Like