Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] Disappearing dice

Author
Message
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 10th Apr 2018 21:37
I'm trying to write a program for dice rolls, you know, RPG and so on. But after some dozens of rolls (sometimes 14, sometimes 25, sometimes 50) the D10 dice I use disappears and its Y coordinate is "nan".

I hope I haven't forgotten about any file

Attachments

Login to view attachments

The author of this post has marked a post as an answer.

Go to answer

TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 11th Apr 2018 10:19
Don't have much time now to try your code, but reading through it, I would guess that the small floating point errors are gradually causing your dice to slip through the table. You might want to reset the position of the dice on each roll.
puzzler2018
User Banned
Posted: 11th Apr 2018 10:40 Edited at: 11th Apr 2018 10:41
Im conerned you wrote


RotX=Random(0,2)-1
RotY=Random(0,2)-1
RotZ=Random(0,2)-1

Why put -1 if it randoms out at 0 the it will return a -1 eventually, remove these and you will be fine

Rather odd proramming
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Apr 2018 12:58
What's wrong with -1? Wouldn't that simply rotate backwards? I don't see why that would cause an issue.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 11th Apr 2018 17:22
That's what I thought about the -1. It's not explained well anywhere :/
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 11th Apr 2018 18:57
This post has been marked by the post author as the answer.
The issue occurs when RotX, RotY and RotZ are all ZERO. This will mess up the angular vector.
The probability for this to happen is ( 1 / 3 ) ^ 3, which is roughly 3.7%. This is why it seems to happen sporadically.

I also wouldn't mess around with the gravity. A better approach is to set a fixed gravity like

and give the dice a push with


PSY


PSY LABS Games
Coders don't die, they just gosub without return
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 11th Apr 2018 21:56
Wow, so it looks like a bug thanks for the solution, it works!
And BTW, what's your advice: leave the dice until it falls asleep without

and reset physics after pressing the button to save energy, or leave it as it is? The load of the processor isn't big, no more than 4% on my computer, but I haven't tested on a smartphone yet.
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 12th Apr 2018 06:13
I'd probably put it to sleep like this:



PSY LABS Games
Coders don't die, they just gosub without return
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 12th Apr 2018 13:47
Thanks!
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 12th Apr 2018 14:43
Anytime


PSY LABS Games
Coders don't die, they just gosub without return
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 19th May 2018 20:37
OK, I modified the program. Now it works fine, but there's another problem: if I rem lines 33 and 34 instead 35 and 36 to change dice type from D10 to D4, after some dozens of rolls it goes through the bottom (or the cover if you press "Roll" button too frequently) and the dice falls down below the floor. It doesn't happen with D10 or any other dice type. I made a workaround that if y coordinate gets too small it creates another D4 in the right place, but it's "dirty" solution Can anybody help me making it work right?

Attachments

Login to view attachments
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 20th May 2018 03:23 Edited at: 20th May 2018 03:24
Strange.
Your code works fine on my machine with both dices.
Even works if I simulate 30 clicks per second.


By the way, this line is useless:
Quote: "If GetVirtualButtonReleased( btnRoll ) =1 then Set3DPhysicsGravity( 0,-5,0)"


PSY


PSY LABS Games
Coders don't die, they just gosub without return
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 21st May 2018 22:14
[video=youtube]https://youtu.be/KsLUIpuW8pw[/video]
but thanks for pointing the useless line
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 22nd May 2018 05:19
Hey,

Thanks for the extensive video!
This is strange. Seems to depend on the shape of the object.

Now it happend on my system, too. Must have been luck during my first try. I clicked slower and waited longer this time.


PSY LABS Games
Coders don't die, they just gosub without return
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 22nd May 2018 05:57 Edited at: 22nd May 2018 05:57
Could be caused by the 'flatness' of the table plane in connection with the shape of the dice.

Have you tried to create a box instead of a plane for the table?


PSY LABS Games
Coders don't die, they just gosub without return
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 28th May 2018 20:55 Edited at: 28th May 2018 20:56
Doesn't work, sorry. I tried adding an additional plane under the bottom and also a box (it was funny when lower vertex of D4 "sank" in the bottom leaving other ones on the surface ), I also tried to "soften" dice's edges. I think it's AGK's engine bug that randomly turns off collision detection. It may be caused by fact that all the angles between the dice's walls are smaller than 90 degrees, I don't know (it's the only difference between D4 and other dices I can think of). Looks like I have to stick to my workaround <sigh>.
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 29th May 2018 02:00
You can not create a static body for an object plane.
The coffee is lovely dark and deep,and I have code to write before I sleep.
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 29th May 2018 10:06
according to the docs, the smallest size that the physics engine can handle is about 3.5 units. A plane is effectively 0 units thick. You should try creating a box at least 3.5 units instead.
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 29th May 2018 22:48 Edited at: 29th May 2018 22:51
Then why does it work with all the other dice types? :o
Besides, the box size I created for testing as the floor was 40,5,40. Didn't work either
Mr TomToad, what docs are you talking about?
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 30th May 2018 03:14
The docs I'm referring to see the agk documentation here https://www.appgamekit.com/documentation/home.html

Specifically the page on Create3dPhysicsWorld() https://www.appgamekit.com/documentation/Reference/3DPhysics/Create3DPhysicsWorld.htm
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 30th May 2018 06:53
Could the 3D model of the dice be broken maybe?

Have you tried to redo it from scratch and slighty change the angles?


PSY LABS Games
Coders don't die, they just gosub without return
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 30th May 2018 20:04
Just imported both dices into Windows 3D builder.
The geometry of the D4 looks weird when you zoom in on the edges.


PSY LABS Games
Coders don't die, they just gosub without return
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 1st Jun 2018 19:14
What do you mean by "the geometry of the D4 looks weird"? I added some "bevel" to soften the edges, that's all. I thought it could solve the problem, but it didn't that "softened" dice worked the same as the basic one, with sharp edges and only four walls. And the angles can't be changed since this would change the probability of particular rolls.
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 2nd Jun 2018 09:09
I played around a bit.
The issue seems to be the scale value of the dice.
Even a scale of 5.0 seems to be too low to handle physics correctly for that D4.
Just use bigger scales on everything, and zoom out the camera to compensate the bigger scales, and you should be fine.


PSY LABS Games
Coders don't die, they just gosub without return
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 2nd Jun 2018 16:10
can you not just adjust the scale factor when setting up the physics?
Create3DPhysicsWorld( scaleFactor )
it says the default is 40 so try something like 20~30.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 2nd Jun 2018 16:37
Should work also, but you'd have to adjust all physics properties like gravitation, spin etc


PSY LABS Games
Coders don't die, they just gosub without return

Login to post a reply

Server time is: 2024-11-23 01:06:04
Your offset time is: 2024-11-23 01:06:04