Constrain drag script

If I will use drag script from needle, and then constrain movement script from unity. Its working in viewport but after build its not. Only drag script from needle. Is there any priority of scripts? Or how lock movement is X,Y axis and allow it only in Z… any sourcee fro studiing?

Original Post on Discord

by user 869976161550217286

By after build you mean when you click play and run it in the browser?

yes

by user 869976161550217286

What is the constraint movement script?

It might not be supported by us and if you want to use it you would have to write a bit of Typescript

here: CAB I need to move roof after drag only up and down… wait I will tell you what I have used

by user 869976161550217286

@marcel :cactus: yes I see, no problem to write or learn type scrip if it will solve my problem. I though that unity scripts and needle scripts can be both used…

by user 869976161550217286

but if not, I should modify or write my own, but I need a little aadvise, where to start

by user 869976161550217286

They can but they basically are just used in Unity to setup your data and settings which is then directly exported to components in Needle Engine (if you have a matching Typescript component) where you can apply the settings. That’s how we translated many Unity components for example (just make a typescript script with the same class name as the Unity class for example)

For getting started checkout Needle Engine Scripting | Needle Engine Documentation
and https://www.youtube.com/watch?v=uf5UK0bLHlY&t=65s&ab_channel=Needle
You’ll also find some small code examples here: Script Examples | Needle Engine Documentation

When you see this blue text on a component it means it is translated/has a matching typescript class. You can click on it to see the code (or to edit it if it’s your own)
image.png

i meean this its position constrain just allow in Y

by user 869976161550217286

Or I can add buttons like OPEN and CLOSED and set OPEN Y position to 100 and CLOSED position to 0 and just animate roof. I need to show whats inside. SO maybe some send to position example in needle should be enought for me

by user 869976161550217286

For the animation you can just setup an animatorcontroller with two states (open and closed) and then make a transition by maybe setting a trigger (from a Unity button onClick event for example)

Similar to your bike example…

by user 869976161550217286

If you want to force it to be on Y you can write:

import { Behaviour } from "@needle-tools/engine";

export class ConstraintYPosition extends Behaviour {

    private _y: number = 0;

    awake(): void {
        this._y = this.gameObject.position.y;
    }

    onBeforeRender(): void {
        this.gameObject.position.y = this._y;
    }
}

image.png

and then add it to the scripts folder (you can open the code editor by clicking this button)
image.png

Just as extra context, that component is unfortunately currently not supported (you see that because it doesn’t have the blue link to a matching TypeScript component below the component header) - so Marcel’s way of adding a new script that does what you need is recommended here

It seems its not working

by user 869976161550217286

@herbst🌵 as you said, OK I have to find some workaround

by user 869976161550217286

You need to try it in the browser. The code it sent is for the web and not for the unity editor :slightly_smiling_face: