Simple Rotation Limiter Node

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

  1. Muspar

    Muspar Boxer

    Joined:
    Sep 27, 2019
    Messages:
    9
    Likes Received:
    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. blhp

    blhp Boxer

    Joined:
    Dec 8, 2015
    Messages:
    5
    Likes Received:
    0
    Thanks a lot for this!
     
  3. MarcG

    MarcG Boxer

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

    volcank Serious Boxer

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

    rizwanashraf Avid Boxer

    Joined:
    Dec 3, 2015
    Messages:
    339
    Likes Received:
    209
    :D haha okay okay :p
     
    volcank likes this.
  6. Josh (Nology Games)

    Josh (Nology Games) Community Manager Staff Member

    Joined:
    Nov 27, 2017
    Messages:
    816
    Likes Received:
    255
    awesome stuff!
     
    volcank likes this.

Share This Page