追 ChatGPTにclusterのスクリプトを書いてもらう方法
この記事で紹介した、ChatGPTにclusterのスクリプトを書いてもらうためのプロンプトについて、もっと良さげなのを発見次第追記していく記事です.
英語で書く
日本語で書くより安定して文法に忠実なコードが返ってきます.
とはいえ文法以外のコード設計ミスなどは変わらず起きるので依然ガチャは必要.
## The required item の部分を書き換えてお使いください. 日本語の要件文をDeeplに通してコピペすれば十分です.
"""
You are a professional programmer.
You program using cluster javascript, a language for manipulating items within a cluster
## The required item
Item vibrating in x-axis direction with a period of 5 seconds and a width of 5 m
##cluster javascript specifications
##Event functions
In cluster javascript, the functions are divided by the timing at which they are executed.
Only the following event functions can be used
$.onUpdate(deltaTime => {
// Describe the processing performed every frame here.
});
$.onGrab(isGrab => {
if (isGrab) {
// Describe the processing performed when the item is grabbed here.
} else {
// Describe the processing performed when the item is released here.
}
});
$.onUse(isDown => {
if (isDown) {
// Describe the processing performed when the item is used here.
}
});
$.onInteract(() => {
// Describe the processing performed when interacting with the item here.
});
$.onRide(isGetOn => {
if (isGetOn) {
// Describe the processing performed when getting on the item here.
} else {
// Describe the processing performed when getting off the item here.
}
});
#State variables
In cluster javascript, global variables cannot be used, instead state variables are used
State variables can be assigned boolean, integer, float or Vector3 values.
State variables must be declared with an initial value in the onUpdate function
For example, a script for an item that measures the time during a ride might look like this
$.onUpdate(deltaTime => {
if (!$.state.initialized) {
$.state.initialized = true;
$.state.riding = false;
$.state.time = 0;
}
if ($.state.riding){
$.state.time += deltaTime;
}
});
$.onRide(isGetOn => {
if(isGetOn){
$.state.riding = true;
$.state.time = 0;
}else{
$.state.riding = false;
}
});
#Manipulating 3D vectors
let a = new Vector3(0, 0, 0);
a = a.clone().add(b); // Add vector b to vector a.
a = a.clone().sub(b); // Subtract vector b from vector a.
a = a.clone().multiply(b); // Multiply vector a by vector b.
a = a.clone().divide(b); // Divide vector a by vector b.
a = a.clone().length(); // Assign the length of vector a to c.
a = a.clone().addScalar(b); // Add scalar b to each element of vector a.
a = a.clone().subScalar(b); // Subtract scalar b from each element of vector a.
a = a.clone().multiplyScalar(b); // Multiply each element of vector a by scalar b.
a = a.clone().divideScalar(b); // Divide each element of vector a by scalar b.
a = new Vector3(a.x, a.y+1, a.z); // Manipulate some elements of vector a.
#Manipulating item position and rotation
Get the XYZ coordinates of the item with Vector3:
let ownposi = $.getPosition();
Move the item to (0, 0, 0):
$.setPosition(new Vector3(0, 0, 0));
Get the Euler angles of the item with Vector3:
let ownrot = $.getRotation().createEulerAngles();
Rotate the item to have Euler angles (0, 0, 0):
$.setRotation(new Quaternion().setFromEulerAngles(new Vector3(0,0,0)));
#Attension
Instead of directly manipulating the elements of a vector, such as a.y += 1, re-generate the vector, such as a = new Vector3(a.x+1, a.y, a.z)
Instead of only performing operations on vectors, such as a.clone().add(b) , explicitly assign the result of the operation to a variable, such as a = a.clone().add(b)
Instead of performing only vector operations, such as a.clone().add(b) , explicitly assign the result of the operation to a variable, such as a = a.clone().add(b)
Instead of using vector arithmetic expressions for numbers, such as $.state.a = 1; $.state.a.multiplyScalar(b); use the usual arithmetic expressions for numbers, such as $.state.a*b.
"""
参考動画
(1発で決めてるように見えるじゃん? …実は5回ぐらいガチャしてる汗)
この記事が気に入ったらサポートをしてみませんか?