Object follow rotation of another object

EDIT : THIS SOLUTION IS NOT WORKING, STILL SEARCHING !
Finally I got it !
From months I could not get a good solution to have an object follow the rotation of another object.
Now I have it, to share with you.


The blend is attached, playable with arrow keys : cubuesque.blend (779.0 KB)
The final game is coming soon :slight_smile:

edit : there is still some imperfections, the object does not always follow the shortest path… it’s almost good, but not perfect. If someone has THE solution, please share.

1 Like

Hi Mokauno,
You recreated the “Lerp” function but with node. I think that’s THE solution.
There is a Lerp vector node in the “Logic_Pack” that make easier to setup:
( get target rotation -> lerp vector -> set rotation )
But the results would be the same as what did with your nodes setup.

I think that the “weird” result you might find some times are due to gimbal lock, and unfortunatly I think there is no “perfect” solution. No matter how you configure it, you’ll always have one angle that will act a bit strange.

I think that to avoid weird rotation you’ll have to find a way to cheat, but it will be complex and might not be worth it.

1 Like

The solution I provided does not work. To prove it, try to run the blend and press 5 times the right arrow key on your keyboard. The cube has to move 5 time to the right, but it move 4 times right, and 1 time left.
bad news… we still don’t have the solution to this problem.

Hi @mokauno,

What exactly are you trying to achieve here? Could you please elaborate.

Hi Mokauno, thank’s for the details, I didn’t noticed it the first time.
I tried fixing it with nodes, but couldn’t find a good solution unfortunately…
You’ll have to use Haxe Script.

I made one based on the Lerp Camera example

package arm;

import iron.math.Quat;

class FollowRotation extends iron.Trait {

	@prop
	var target : iron.object.Object; //= iron.Scene.active.getChild("main_cube_Empty_target");
	@prop
	var follow : iron.object.Object; // = iron.Scene.active.getChild("main_cube_Empty");
	@prop
	var speed : Float = 0.1;

    public function new() {
	    super();

	    // notifyOnInit(function() {
	    // });

	    notifyOnUpdate(function() {

	
		    if (target.transform.rot != follow.transform.rot){
			    var newRot = new Quat().lerp(follow.transform.rot, target.transform.rot, speed);
			    follow.transform.rot.setFrom(newRot);
			    follow.transform.buildMatrix();
		    }

	    });

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

Don’t forget to clic on Refresh the script when you finished to make the variables appeat in the “Traits Properties” panels.
Also make sure you have setted something in the “Target” and “Follow” property or you’ll have an error in the console and thhe game wont boot.

I hope you can make it work.

1 Like

Actually, I use Euler/angle and it works, the rotating object has just little deformations.
@QuantumCoderQC I’m trying to have an object to rotate to an objective.
@Hikibob thanks for your effort, I will try.