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
#Slot Game Help
1 messages · Page 1 of 1 (latest)
{
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;
}```
if you're using <=, decimals shouldn't matter
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
ah, so it's not landing perfectly?
so set its position?
this is a cheated way to do it
i did set its position but its still off
and idk why
make sure you're setting the pos correctly
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)
just set the final roll before stopping
(slot 1 = panda, slot 2 = coin, slot 3 = whatever)
and when you stop
set the pos accordingly
thats what I tried to do here but the y position never equaled the wanted final position
unless im misinterpreting what youre saying
so set it
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
yes
i guess I dont have a print statemtns to check that
one sec
more than 3 times
no idea why
case 5's selection is not equal to the y position you're setting
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
sorry what do you mean
boolean spinning = true
y position = specific position
spinning = false
while(spinning)
// spin
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
no
that should have 2 decimals max
but when is that
Try to use transform.localPosition instead of transform.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
}
ill try this really quick
wouldnt know enough about it to understand the diff but ill try it
while spinning: spin.
done spinning? don't spin anymore.
that simple
localPosition is relative to the parent
does your object have a parent?
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
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
so is this causeing all my problems?
shoudl I remove parent
😮💨
Im so fucking sorry man
when are you stopping the spinning?
instantly when the y value hits your target?
or after a period of time
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
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
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
lmao
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
yeah cant say I properly know how to do this
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.
just yield return null
but then wont it still scroll insanely quick?
cause im using that to stall for a bit till it does the next movement
you messed something up with the transforms
it's not deltatime tho
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
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
😮💨