プレイ日記
*J.P.* DEV NEWPICY3
this code is supposed to be enemy movement done right but when i use it in my code is say "divide by zero in (line num)" does anyone know the problem?
3そうだね
プレイ済み
返信[1]
親投稿
raimondz raimondzz
That code doesn't work if X==X2. The same with Y and Y2.
0そうだね
プレイ済み
返信[2]
親投稿
Hanzo rzsense
I guess that the purpose of this code is an enemy's constant speed approach to a player. The denominator of this code stands for the distance between a player and an enemy. When divide by zero error occurs, an enemy has already collided with a player.
0そうだね
未プレイ
返信[3]
親投稿
Hanzo rzsense
You should replace both two denominators with the following code. SQR(POW(X2-X,2)+POW(Y2-Y,2))
0そうだね
未プレイ
返信[4]
親投稿
*J.P.* DEV NEWPICY3
ok thank you. ill tell you if this works
0そうだね
プレイ済み
返信[5]
親投稿
Hanzo rzsense
Write as follows in order to kill divide by zero error. D=SQR(POW(X2-X,2)+POW(Y2-Y,2)) IF D>0 THEN X2=X2+(X2-X)/D:Y2=Y2-(Y2-Y)/D The following code is another solution. D=SQR(POW(X2-X,2)+POW(Y2-Y,2)) IF D>0 THEN A=ATAN(Y-Y2,X-X2) X2=X2+COS(A):Y2=Y2+SIN(A) ENDIF
1そうだね
未プレイ
返信[6]
親投稿
*J.P.* DEV NEWPICY3
thank you very much btw! but i have one more question, i would like to make the enemy sprite follow my sprite realistically, i have done this before but it dosent seem to be working now. so basically the enemy sprite homes in on the middle of the screen where the player is.
0そうだね
プレイ済み
返信[7]
親投稿
Hanzo rzsense
I overlooked suspicious points. Could you replace X2=X2+(X2-X)/D:Y2=Y2+(Y2-Y)/D with X2=X2+(X-X2)/D:Y2=Y2+(Y-Y2)/D ? An enemy will LEAVE a player with the former code.
0そうだね
未プレイ
返信[8]
親投稿
*J.P.* DEV NEWPICY3
thank you!
0そうだね
プレイ済み