#Slot Game Help

1 messages · Page 1 of 1 (latest)

valid helm
#

to start off, im adding a little bit of a slot game aspect into my main game for once the player loses a round ( a way for them to win coins or a free play back). Im using the transform.position.y to move the slot down and to bring it back to the start if it gets to the bottom as seen in the picture Ill add. however im trying to get it to stop on one of the 5 items in the reel and when I check the transform.position.y it alwasy seems to have extra decimals or it doesnt line up with what it is supposed to or what it says in the code. This is also my first time using enumerators so please bear with me

#
    {
        rowStopped = false;
        timeInterval = 0.04f;

        for (int i = 0; i < 60; i++)
        {
            if (transform.position.y <= -3.78f)
            {
                transform.position = new Vector2(transform.position.x, 6.22f);
            }

            transform.position -= new Vector3(0, 0.01f, 0);
            print(transform.position.y);

            yield return new WaitForSeconds(timeInterval);

        }

        randomValue = Random.Range(1, 6);


        //tells us which item we want to stop on

        switch(randomValue)
        {
            case 1:
                //this is a 10coin
                selection = -3.78f;
                //transform.position = new Vector3(transform.position.x, -3.78f, 0);
                break;

            case 2:
                //this is a 5coin
                selection = -1.78f;
                //transform.position = new Vector3(transform.position.x, -1.78f, 0);
                break;

            case 3:
                //this is a key
                selection = 0.22f;
                //transform.position = new Vector3(transform.position.x, 0.22f, 0);
                break;

            case 4:
                //this is a costume
                selection = 2.22f;
                //transform.position = new Vector3(transform.position.x, 2.22f, 0);
                break;

            case 5:
                //this is a costume
                selection = 6.22f;
                //transform.position = new Vector3(transform.position.x, 4.22f, 0);
                break;
        }

        
        while(transform.position.y != selection)
        {
            if (transform.position.y <= -3.57f)
            {
                transform.position = new Vector2(transform.position.x, 6.22f);
            }

            transform.position -= new Vector3(0, 0.01f, 0);


            print("the y position is: " + transform.position.y);
            yield return new WaitForSeconds(timeInterval);
        }


        

        //Play sound
        stopSound.Play();
        print("final position is: " + transform.position.y);

        if (transform.position.y == -3.78f)
            stoppedSlot = "10Coin";
        else if (transform.position.y == -1.78f)
            stoppedSlot = "5Coin";
        else if (transform.position.y == 0.22f)
            stoppedSlot = "freePlay";
        else if (transform.position.y == 2.22f)
            stoppedSlot = "key";
        else if (transform.position.y == 4.22f)
            stoppedSlot = "Costume";
        else if (transform.position.y == 6.22f)
            stoppedSlot = "10Coin";

        rowStopped = true;
    }```
wintry mango
#

if you're using <=, decimals shouldn't matter

valid helm
#

it brings it back to the top, but I have some print statements and they are simply not outputting what i see on the game

wintry mango
#

ah, so it's not landing perfectly?

valid helm
#

yeah

#

and like

wintry mango
#

so set its position?

valid helm
#

this is a cheated way to do it

#

i did set its position but its still off

#

and idk why

wintry mango
#

where are you setting it

#

and are you sure you're on point?

valid helm
#

but id prefer to use this

wintry mango
#

make sure you're setting the pos correctly

valid helm
#

is there a different way? how would I make sure? im used to just setting it like I did in the switch case

#

but I would prefer to use the while loop and have it stop once it hits the icon

#

is it something to do with enumerators i dont understand

#

cause the final position gets posted like 100 times when i though it would be posted 3 times max (one for each reel)

wintry mango
#

just set the final roll before stopping

#

(slot 1 = panda, slot 2 = coin, slot 3 = whatever)

#

and when you stop

#

set the pos accordingly

valid helm
#

thats what I tried to do here but the y position never equaled the wanted final position

#

unless im misinterpreting what youre saying

wintry mango
#

so set it

valid helm
#

I do for now in the switch case

#

and it doesnt work

#

absolutely no idea why

#

has to be somethign with this enumerator I think because it also runs these lines way more often than I would like

wintry mango
#

I would rework your logic

#

also is it even running?

valid helm
#

yeah

#

you mean the switch case?

wintry mango
#

yes

valid helm
#

i guess I dont have a print statemtns to check that

#

one sec

#

more than 3 times

#

no idea why

wintry mango
#

case 5's selection is not equal to the y position you're setting

valid helm
wintry mango
#

instead of this

        while(transform.position.y != selection)
        {
            if (transform.position.y <= -3.57f)
            {
                transform.position = new Vector2(transform.position.x, 6.22f);
            }

            transform.position -= new Vector3(0, 0.01f, 0);


            print("the y position is: " + transform.position.y);
            yield return new WaitForSeconds(timeInterval);
        }

make a boolean and just run it while it's not true, setting it when you set the y pos

valid helm
#

sorry what do you mean

wintry mango
#

boolean spinning = true
y position = specific position
spinning = false

#

while(spinning)
// spin

valid helm
#

stop spinning once y.pos is the same as selection?

#

I feel like that is the exact same thing... and the problem with that is my y.pos tunes into big decimals after like a millisecond

wintry mango
#

no

valid helm
#

that should have 2 decimals max

wintry mango
#

stop spinning when you're done spinning

#

(aka spinning == false)

valid helm
#

but when is that

wintry mango
#

when you land

#

when you set the position

grizzled mountain
#

Try to use transform.localPosition instead of transform.position

valid helm
# wintry mango when you set the position

im trying so hard to interpret what youre saying and i literally cant.

while(spinning){

transform it 0.01f down 
run random.range
get a random selection
set position of object to random selection

spinning = false
}

valid helm
#

wouldnt know enough about it to understand the diff but ill try it

wintry mango
#

that simple

wintry mango
#

does your object have a parent?

valid helm
#

i put them inside an empty object

#

so like yeah

wintry mango
#

so it will affect it then

#

if parent is at 10, 3 and child pos is at 10, 3 as well, localPosition will be 0, 0, position will be 10, 3

valid helm
# wintry mango that simple

not that simple to me...because i dont know how to find out if its done spinning because the y.pos is never equal to the selected value

valid helm
#

shoudl I remove parent

wintry mango
#

😮‍💨

valid helm
#

Im so fucking sorry man

wintry mango
#

instantly when the y value hits your target?

#

or after a period of time

valid helm
#

I do 60 movements first (to show some spinning) then i have my switch case to choose a selection, and then i wanted to while loop it to spin until it hits the selected

wintry mango
#

are you changing transform.position without deltaTime?

#

that'll break stuff

valid helm
#

no, whenever I loop to move the object I use wait for seconds (timeinterval) to delay it a bit to make it a smooth spin or else itll happen waaayyy too fast

#

so like is that breaking my shit too

wintry mango
#

yeah... so use deltaTime

#

not wait intervals

valid helm
#

okay so before I do that... I just removed parent

#

and um

#

yeah that was a lot of my problems

#

I did not know that it worked like that omfg

#

okay one sec

wintry mango
#

lmao

valid helm
#

So i didnt change any of the delta time stuff but with the parent gone and then some values changed because the parent is gone

#

the stop now stops them in the right place

#

so now I may be able to do the while loop to stop them

#

so again

#

gimme another sec

#

I fucking lovve you for sticking through this with my absolute braindead self

#

okay so it still goes into crazy decimals while spinning

#

so the while loop checking if its equal to the selection wont work

#

but youre saying this could be because im not using delta time?

#

I see what yorue saying now

#

now to try an implement this

valid helm
wintry mango
#

Vector3 * Time.deltaTime

#

will slow it down to the framerate so someone playing at 144 fps won't have a faster anim than someone at, say, 30.

valid helm
#

so from this...to this?

#

but you want me to remove the waitforseconds?

wintry mango
#

just yield return null

valid helm
#

but then wont it still scroll insanely quick?

#

cause im using that to stall for a bit till it does the next movement

wintry mango
#

deltatime slows stuff down

#

try it

valid helm
#

...

#

it overlapped them

#

lmao what thats whacky

wintry mango
#

you messed something up with the transforms

valid helm
#

for sure

#

lol

wintry mango
#

it's not deltatime tho

valid helm
#

the two screenshots i sent was all i changed

#

i added the *time.delta time at the end

#

wait

#

this thing is so fucked now lmao

wintry mango
#

lmfao

#

F

valid helm
#

its soooo buggy now with the time.deltatime

#

I agree I should be using it after the little bit of research

#

but i just dont know how to implement it

#

so now I ask myself if thats the reason that it goes into decimals

#

when scrolling

wintry mango
#

😮‍💨

valid helm
#

hey man thanks for the help, ima grab some food because ive been stuck on this for so long and the fact that I still dont know why is painful

#

I appreciate it a lot

#

<3