何が起こっていて、何週間も私を殺していたのかをうまく組み立てることができました。それが私のミスなのか、単にキーを押すのが速すぎたのか、レンダリングが遅れたのかを本当に知りたかったのですか? 問題に対処するために、私はそうする犯人を見つけていないので.
これは、たとえば、斜め下から右、左、右に移動してから、下に戻るときに発生します。そのような動きをすばやく行います。常に発生するとは限りませんが、ゲームを混乱させるのに十分です.
移動スクリプト:
extends KinematicBody2D
var velocity = 150
var direction = Vector2()
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
#-----------MOVIMENT-------------------------------
direction = Vector2()
#LEFT
if Input.is_action_pressed("left"):
direction += Vector2(-1, 0)
#RIGHT
elif Input.is_action_pressed("right"):
direction += Vector2(1, 0)
#UṔ
if Input.is_action_pressed("up"):
direction += Vector2(0, -1)
#DOWN
elif Input.is_action_pressed("down"):
direction += Vector2(0, 1)
if direction.x != 0 || direction.y != 0:
direction = direction.normalized()*velocity
move(direction*delta)
ペイント スクリプト:
extends Control
var map_size = 64
var preScriptUtils = preload("res://scripts/utils_fuctions.gd")
var utils_functions
onready var player = $"../Player"
onready var tile_map = $"../TileMap"
var posTileMap = Vector2()
var posWorld = Vector2()
var prevRect = Rect2()
var newRect = Rect2()
var distance_gen = 2048
var positionMap_rect = 0
var size_rectMap = 0
func _ready():
utils_functions = preScriptUtils.utils_functions.new()
set_fixed_process(true)
posWorld = Vector2(0, 0)
positionMap_rect = ((distance_gen/32)/2)
size_rectMap = distance_gen/32
surround_map(posWorld)
func _fixed_process(delta):
var posPlayer = player.get_position()
posTileMap = tile_map.world_to_map(posPlayer) - Vector2(positionMap_rect, positionMap_rect)
newRect = Rect2(tile_map.map_to_world(posTileMap), Vector2(distance_gen, distance_gen))
if prevRect.position != newRect.position:
load_newMap()
func gen_data(var _posWorld=Vector2(0, 0), var _posTileMap=Vector2(0, 0), var size=Vector2(0, 0)):
var x = 0
var y = 0
var pos_modx = 0
var pos_mody = 0
while x < size.x:
y = 0
pos_modx = utils_functions.mod(_posWorld.x + x, map_size)
#NOISE
var result_noise
while y < size.y:
pos_mody = utils_functions.mod(_posWorld.y + y, map_size)
if (pos_modx >= 0 && pos_mody >= 0) && (pos_modx < map_size && pos_mody < map_size):
tile_map.set_cell(_posTileMap.x + x, _posTileMap.y + y, biomes(result_noise))
y += 1
x += 1
func load_newMap():
var rectIntersection = newRect.clip(prevRect)
var _x = 0
var _y = 0
#LEFT
if player.direction.x < 0:
if int((newRect.size.x - rectIntersection.size.x)/32) == 1:
_x = int(newRect.position.x/32)
_y = int(rectIntersection.position.y/32)
posWorld.x -= 1
gen_data(Vector2(posWorld.x, posWorld.y), Vector2(_x, _y), Vector2(1, size_rectMap))
#RIGHT
elif player.direction.x > 0:
if int((newRect.size.x - rectIntersection.size.x)/32) == 1:
_x = int(rectIntersection.end.x/32)
_y = int(rectIntersection.position.y/32)
posWorld.x += 1
Vector2(_x, _y)
gen_data(Vector2(posWorld.x - 1, posWorld.y), Vector2(_x, _y), Vector2(1, size_rectMap))
#UP
if player.direction.y < 0:
if int((newRect.size.y - rectIntersection.size.y)/32) == 1:
_x = int(newRect.position.x/32)
_y = int(newRect.position.y/32)
posWorld.y -= 1
gen_data(Vector2(posWorld.x, posWorld.y), Vector2(_x, _y), Vector2(size_rectMap, 1))
#DOWN
elif player.direction.y > 0:
if int((newRect.size.y - rectIntersection.size.y)/32) == 1:
_x = int(rectIntersection.position.x/32)
_y = int(rectIntersection.end.y/32)
posWorld.y += 1
gen_data(Vector2(posWorld.x, posWorld.y - 1), Vector2(_x, _y), Vector2(size_rectMap, 1))
prevRect = newRect
func surround_map(var _posWorld=Vector2(0, 0)):
posTileMap = - Vector2(positionMap_rect, positionMap_rect)
prevRect = Rect2(tile_map.map_to_world(posTileMap), Vector2(distance_gen, distance_gen))
gen_data(_posWorld, Vector2(-32, -32), Vector2(64, 64))
コードに煩わされないでください。私がやろうとしていることは非常に単純です。世界を生成している間にプレーヤーを動かしたいのですが、4方向で完全に機能しますが、対角線が含まれているとうまくいきません予想通り。私はこのようにペイントしています。各フレームと比較する 2 つの四角形があります。インターセプトの retagunlo を取得し、どこをペイントまたは消去する必要があるかを計算します。
何が起こっているかのビデオ:
http://www.dailymotion.com/video/x6286px
しかし、これらの欠陥は、プレスが速すぎることだけでなく、スローモーションでも発生しますが、斜めに右下、次に左または左または右に戻り、斜めに移動することが問題のようです.たくさんの形を試しました。これを理解しようとして、ほぼすべての落書きがノートに書かれています。斜めのチェックも試してみましたが、同じ結果が得られました。今日は別の日を失いましたが、その場所を離れません。このような数週間、私がそれを修正したと思うとき、実際にはそうではありません。
ゴドーを使用しています。
上 1:
@ Ryan1729の応答で、私は本当に間違った方法で考えていたことに気付きましたが、以下のようなことをしてロジックを修正しようとすると、エラーが続き、混乱しています:
if direction.x != 0 || direction.y != 0:
var vetor_normalized = direction.normalized()
if abs(vetor_normalized.x) < 1 && abs(vetor_normalized.y) < 1:
var vx = Vector2(direction.x, 0)
var vy = Vector2(0, direction.y)
vx = vx.normalized()*velocity
move(vx*delta)
vy = vy.normalized()*velocity
move(vy*delta)
else:
direction = direction.normalized()*velocity
move(direction*delta)
上2:
今、私はそうしました、それは欠陥を解決したようですが、私はまだ理解していない他の欠陥が現れました.0の問題は私を混乱させすぎます.
var oldPosWorld = Vector2(0, 0)
var rect_tileMap = Vector2(-32, -32)
func load_newMap():
var posPlayer = Vector2(int(player.get_position().x/32), int(player.get_position().y/32))
#LEFT
if posPlayer.x < oldPosWorld.x:
pos_tileMap.x -= 1
posWorld.x -= 1
gen_data(Vector2(posWorld.x, posWorld.y), Vector2(pos_tileMap.x, pos_tileMap.y), Vector2(1, size_rectMap))
#RIGHT
elif posPlayer.x > oldPosWorld.x:
pos_tileMap.x += 1
posWorld.x += 1
gen_data(Vector2(posWorld.x - 1, posWorld.y), Vector2(pos_tileMap.x + 63, pos_tileMap.y), Vector2(1, size_rectMap))
#UP
if posPlayer.y < oldPosWorld.y:
pos_tileMap.y -= 1
posWorld.y -= 1
gen_data(Vector2(posWorld.x, posWorld.y), Vector2(pos_tileMap.x, pos_tileMap.y), Vector2(size_rectMap, 1))
#DOWN
elif posPlayer.y > oldPosWorld.y:
pos_tileMap.y += 1
posWorld.y += 1
gen_data(Vector2(posWorld.x, posWorld.y - 1), Vector2(pos_tileMap.x, pos_tileMap.y + 63), Vector2(size_rectMap, 1))
oldPosWorld = posPlayer
右と下の動きは正しいです。問題は、この空のスペースに残っている左と上の動きです(つまり、ネガを処理します)。
問題を解決するために x - 1 を左に置くと、次のようになります。
私はこれを変更して解決しました:
var posPlayer = Vector2(int(player.get_position().x/32), int(player.get_position().y/32))
このようなチェックによって:
if ((player.get_position().x)/32)
しかし今、私は横に行ってから上に行くことでこれを取得します:
上 3:
間違えてイライラしないように気を使うつもりはありませんが、テストを行ったところ、失敗は止まりました。int (player.get_position (. X / 32) を oldPosWorld.x に個別に割り当てると、コードは次のようになります。これは、y にもそれぞれ割り当てます。エラーが発生しました。アップダウン if を入力すると、以前の x の位置のままだったので、適切なタイミングですべてが更新されます。
左と上はまだそうです:
その理由はよくわかりませんが、率直に言って、疲れすぎて見ることができないのはすぐにはわかりません. しかし、誤解しないように理解したいと思います。これとは別に、期待どおりに現在起こっているようです。
#LEFT
if int(player.get_position().x/32) < oldPosWorld.x:
rect_tileMap.x -= 1
posWorld.x -= 1
gen_data(Vector2(posWorld.x, posWorld.y), Vector2(rect_tileMap.x, rect_tileMap.y), Vector2(1, size_rectMap))
oldPosWorld.x = int(player.get_position().x/32)