ページ 1 / 1
解決)目標位置へ細かい方向で細かくジャンプ
Posted: 2022年2月03日(木) 17:47
by こめかみ
お世話になっております。
添付画像のように起点(モンスター)から見た目標(プレイヤー)のいる色分けしたエリアの位置(X距離とY距離の比率を0.5~2まで四捨五入して(2:0) (1.5:0.5) (1:1) (0.5:1.5) (0:2)にマイナスを含めた16種類)にジャンプ したいです。
どのような記述をすれば良いでしょうか。
0.5刻みで飛べるのはデフォルトのようですが、トリアコンタン様の半歩移動プラグインを使用しております。
コード: 全て選択
this.jump(this.x - $gamePlayer.x, this.y - $gamePlayer.y)
イベントを目標(プレイヤー)までジャンプさせる上記のスクリプトを
最小距離まで分割してジャンプさせようとしてみたのですが
コード: 全て選択
this.jump((Math.round(($gamePlayer.x - this.x)/Math.min(Math.abs($gamePlayer.x - this.x),Math.abs($gamePlayer.y - this.y))|0))*0.5 ,(Math.round(($gamePlayer.y - this.y)/Math.min(Math.abs($gamePlayer.x - this.x),Math.abs($gamePlayer.y - this.y))|0))*0.5)
上記だとX軸とY軸のどちらかが0の場合はダメ&2点間が鋭角になると1度のジャンプ距離が長くなってしまいました。
説明がわかりにくく申し訳ありません。
Re: 解決中)目標位置へ細かい方向で細かくジャンプ
Posted: 2022年2月04日(金) 01:29
by フラクタル
こんにちは。
なんとなくでスクリプトを組み上げてみたのですが、こんな感じでしょうか。
これを実行するイベントは並列処理、$gameMap.event(1)にはエネミーシンボルが入っています。
また変数にはトリアコンタン様のFloatVariables.js(
https://plugin.fungamemake.com/archives/1161)にて少数を可能にしております。
コード: 全て選択
♦ループ
♦ラベル:スタート
♦ウェイト:20フレーム
♦変数の操作:#0003 x距離 = this.character(-1).x - $gameMap.event(1).x
♦変数の操作:#0004 y距離 = this.character(-1).y - $gameMap.event(1).y
♦条件分岐:スクリプト:Math.abs($gameVariables.value(3)) + Math.abs($gameVariables.value(4)) <= 2
♦戦闘の処理:こうもり
♦
:分岐終了
♦条件分岐:x距離 = 0
♦スクリプト: if(2 < $gameVariables.value(4)){$gameMap.event(1).jump(0,2)};
: if(0 < $gameVariables.value(4) && $gameVariables.value(4) <= 2){$gameMap.event(1).jump(0,1)};
: if(-2 <= $gameVariables.value(4) && $gameVariables.value(4) < 0){$gameMap.event(1).jump(0,-1)};
: if($gameVariables.value(4) < -2){$gameMap.event(1).jump(0,-2)};
♦ラベルジャンプ :スタート
♦
:分岐終了
♦条件分岐: y距離 = 0
♦スクリプト: if(2 < $gameVariables.value(3)){$gameMap.event(1).jump(2,0)};
: if(0 < $gameVariables.value(3) && $gameVariables.value(4) <= 2){$gameMap.event(1).jump(1,0)};
: if(-2 <= $gameVariables.value(3) && $gameVariables.value(4) < 0){$gameMap.event(1).jump(-1,0)};
: if($gameVariables.value(3) < -2){$gameMap.event(1).jump(-2,0)};
♦ラベルジャンプ :スタート
♦
:分岐終了
♦条件分岐:スクリプト:Math.abs(Math.abs($gameVariables.value(3)) - Math.abs($gameVariables.value(4))) > 2
♦条件分岐:スクリプト:Math.abs($gameVariables.value(3)) >= Math.abs($gameVariables.value(4))
♦スクリプト:if($gameVariables.value(3) > 0){
: if($gameVariables.value(4) > 0){
: $gameMap.event(1).jump(1.5,0.5)
: }else{$gameMap.event(1).jump(1.5,-0.5)}
: }else{
: if($gameVariables.value(4) > 0){
: $gameMap.event(1).jump(-1.5,0.5)
: }else{$gameMap.event(1).jump(-1.5,-0.5)}
: }
♦ラベルジャンプ:スタート
♦
:それ以外のとき
♦スクリプト: if($gameVariables.value(3) > 0){
if($gameVariables.value(4) > 0){
$gameMap.event(1).jump(0.5,1.5)
}else{$gameMap.event(1).jump(0.5,-1.5)}
}else{
if($gameVariables.value(4) > 0){
$gameMap.event(1).jump(-0.5,1.5)
}else{$gameMap.event(1).jump(-0.5,-1.5)}
}
♦ラベルジャンプ:スタート
♦
:分岐終了
♦
:それ以外の時
♦スクリプト:if($gameVariables.value(3) > 0){
if($gameVariables.value(4) > 0){
$gameMap.event(1).jump(1.0,1.0)
}else{$gameMap.event(1).jump(1.0,-1.0)}
}else{
if($gameVariables.value(4) > 0){
$gameMap.event(1).jump(-1.0,1.0)
}else{$gameMap.event(1).jump(-1.0,-1.0)}
}
♦ラベルジャンプ:スタート
♦
:分岐終了
♦
:以上繰り返し
♦
ただもしかしたらどこかでコピペミスが起きてるかもしれません…(長すぎる)
Re: 解決中)目標位置へ細かい方向で細かくジャンプ
Posted: 2022年2月05日(土) 00:09
by こめかみ
>フラクタル様
ご回答ありがとうございます。
併用プラグインの仕様で、「ジャンプを行う"該当イベントの移動ルート内スクリプト"にてthis.jump()記述をする」必要があり当該イベント以外の場合も「"該当イベントを指定した移動ルート内スクリプト"でthis.jump()を使用しなければ反応しない」という問題が発覚しました。
情報不足による手間をお掛けし、大変申し訳ございません。
先ほど解決案が出たのですが、変数に小数点以下が代入できない問題をトリアコンタン様のFloatVariables.jsにて解決させて頂きました!ありがとうございます!
フラクタル さんが書きました:こんにちは。
なんとなくでスクリプトを組み上げてみたのですが、こんな感じでしょうか。
これを実行するイベントは並列処理、$gameMap.event(1)にはエネミーシンボルが入っています。
また変数にはトリアコンタン様のFloatVariables.js(
https://plugin.fungamemake.com/archives/1161)にて少数を可能にしております。
コード: 全て選択
♦ループ
♦ラベル:スタート
♦ウェイト:20フレーム
♦変数の操作:#0003 x距離 = this.character(-1).x - $gameMap.event(1).x
♦変数の操作:#0004 y距離 = this.character(-1).y - $gameMap.event(1).y
♦条件分岐:スクリプト:Math.abs($gameVariables.value(3)) + Math.abs($gameVariables.value(4)) <= 2
♦戦闘の処理:こうもり
♦
:分岐終了
♦条件分岐:x距離 = 0
♦スクリプト: if(2 < $gameVariables.value(4)){$gameMap.event(1).jump(0,2)};
: if(0 < $gameVariables.value(4) && $gameVariables.value(4) <= 2){$gameMap.event(1).jump(0,1)};
: if(-2 <= $gameVariables.value(4) && $gameVariables.value(4) < 0){$gameMap.event(1).jump(0,-1)};
: if($gameVariables.value(4) < -2){$gameMap.event(1).jump(0,-2)};
♦ラベルジャンプ :スタート
♦
:分岐終了
♦条件分岐: y距離 = 0
♦スクリプト: if(2 < $gameVariables.value(3)){$gameMap.event(1).jump(2,0)};
: if(0 < $gameVariables.value(3) && $gameVariables.value(4) <= 2){$gameMap.event(1).jump(1,0)};
: if(-2 <= $gameVariables.value(3) && $gameVariables.value(4) < 0){$gameMap.event(1).jump(-1,0)};
: if($gameVariables.value(3) < -2){$gameMap.event(1).jump(-2,0)};
♦ラベルジャンプ :スタート
♦
:分岐終了
♦条件分岐:スクリプト:Math.abs(Math.abs($gameVariables.value(3)) - Math.abs($gameVariables.value(4))) > 2
♦条件分岐:スクリプト:Math.abs($gameVariables.value(3)) >= Math.abs($gameVariables.value(4))
♦スクリプト:if($gameVariables.value(3) > 0){
: if($gameVariables.value(4) > 0){
: $gameMap.event(1).jump(1.5,0.5)
: }else{$gameMap.event(1).jump(1.5,-0.5)}
: }else{
: if($gameVariables.value(4) > 0){
: $gameMap.event(1).jump(-1.5,0.5)
: }else{$gameMap.event(1).jump(-1.5,-0.5)}
: }
♦ラベルジャンプ:スタート
♦
:それ以外のとき
♦スクリプト: if($gameVariables.value(3) > 0){
if($gameVariables.value(4) > 0){
$gameMap.event(1).jump(0.5,1.5)
}else{$gameMap.event(1).jump(0.5,-1.5)}
}else{
if($gameVariables.value(4) > 0){
$gameMap.event(1).jump(-0.5,1.5)
}else{$gameMap.event(1).jump(-0.5,-1.5)}
}
♦ラベルジャンプ:スタート
♦
:分岐終了
♦
:それ以外の時
♦スクリプト:if($gameVariables.value(3) > 0){
if($gameVariables.value(4) > 0){
$gameMap.event(1).jump(1.0,1.0)
}else{$gameMap.event(1).jump(1.0,-1.0)}
}else{
if($gameVariables.value(4) > 0){
$gameMap.event(1).jump(-1.0,1.0)
}else{$gameMap.event(1).jump(-1.0,-1.0)}
}
♦ラベルジャンプ:スタート
♦
:分岐終了
♦
:以上繰り返し
♦
ただもしかしたらどこかでコピペミスが起きてるかもしれません…(長すぎる)
Re: 解決中)目標位置へ細かい方向で細かくジャンプ
Posted: 2022年2月05日(土) 00:39
by こめかみ
くろうど様
memberlist.php?mode=viewprofile&u=349
よりご助言頂きまして、なんとか解決に至りました!
↓
https://twitter.com/i/status/1489630983871950849
該当イベントの移動ルートスクリプトにてイベントidを取得
コード: 全て選択
$gameVariables.setValue(変数(id),this._eventId)
コモンイベントのスクリプトにて目標と該当イベント間の距離から角度を取得
さらにその変数(角度)を360度/16エリア(22.5度刻み)で条件分岐
エリア毎のジャンプ距離の数値を変数(X値)と変数(Y値)に整数で代入
コード: 全て選択
θ = Math.atan2(目標x - 変数(id)x, 目標y - 変数(id)y);
deg = θ*180/Math.PI;
$gameVariables.setValue(変数(角度),deg);
該当イベントの移動ルートスクリプトにてジャンプさせる
HalfMove.jsの使用前提でFloatVariables.js(トリアコンタン様)を導入し0.5掛けで移動距離を細かくする
コード: 全て選択
this.jump(変数(X値)*0.5,変数(Y値)*0.5)
JumpSpeedCustomize.js(トリアコンタン様)にてジャンプの速度・高さを任意で調節
コモンのスクリプトの最後にウェイトを挟み追尾する間隔を任意で調節
かなり力技になりましたが以上で解決いたしました。
自分以外で用途があるかはわかりませんが、どなたかの参考になればと思います。
※別途くろうど様が別アプローチによるプラグインを作成なされています