# Simple Rotation Limiter Node

Discussion in 'BBNodes' started by Muspar, Oct 5, 2019.

Tags:
1. ### MusparBoxer

Joined:
Sep 27, 2019
Messages:
9
4
Sorry if this is the wrong place for this. In my most recent game, I needed a way to limit a kinematic object's rotation to stay within certain bounds while using the touch rotate control node. There may be a way to do this natively in Buildbox but I couldn't find it. So I modified the Position Limiter node so that it would lock the object's XYZ rotation instead of position and figured other people might find this useful too.

To do this, drag a Position Limiter node into the object's node map, then edit the code and replace it with the code at the end of my post. Then you can enter the minimum and maximum values just like you would in a regular position limiter node and the object won't rotate outside of those bounds.

var _max;
var _min;
var _enabled = false;
function init(){
_max = this.attribute('Max');
_min = this.attribute('Min');
}

function start(){

}

function update(dt){
if(!_enabled){
return;
}

let rot = this.entity().rotation();
if(rot.x > _max.x){
rot.x = _max.x;
}
if(rot.y > _max.y){
rot.y = _max.y;
}
if(rot.z > _max.z){
rot.z = _max.z;
}

if(rot.x < _min.x){
rot.x = _min.x;
}
if(rot.y < _min.y){
rot.y = _min.y;
}
if(rot.z < _min.z){
rot.z = _min.z;
}

this.entity().setRotation(rot.x, rot.y, rot.z);
}

function signal(name, value){
_enabled = value;
}

2. ### blhpBoxer

Joined:
Dec 8, 2015
Messages:
5
0
Thanks a lot for this!

3. ### MarcGBoxer

Joined:
May 10, 2020
Messages:
35
9
Thank you, this solved an issue for me.

4. ### volcankSerious Boxer

Joined:
Oct 8, 2015
Messages:
745
352
I couldn't appreciate this more man! Thank you so much just what I needed at the moment!

5. ### rizwanashrafAvid Boxer

Joined:
Dec 3, 2015
Messages:
339
209 haha okay okay volcank likes this.

Joined:
Nov 27, 2017
Messages:
816