#Need help with simple if else conditionals

1 messages · Page 1 of 1 (latest)

austere thorn
#

Basically I want my bool object variable to be false if the Position Z of my object is greater than or equal to 22 or true if the Position Z of my object variable is less than or equal to 16.

The variable, called isLeft basically indicates whether the platform will be moving left or right (isLeft = true meaning that its traveling left and vice versa). This is so that platform can move back and forth only between its Position Z values of 16 and 22; when the platform reaches 16 itll start moving right till it hits 22 then starts moving left again.

I'm forced to use visual scripting due to my course but they didn't teach us anything yet so I'm unable to use regular scripting for this.

How can I do this?

crude shell
#

i think those 2x if nodes and 2x boolean nodes can be removed

#

you can drag the result from your comparison nodes directly into setVariable

austere thorn
#

They are still grayed out, is this fine?

crude shell
#

ah that's what you're misunderstanding, execution flow

austere thorn
#

Sorry if this is a basic question, I only know regular programming and haven't ever used a visual scripting tool like this before

crude shell
#

you can draw on chains of properties without executing them, but at some point they need to be plugged into a node that is part of the execution flow

#

so in other words, your green arrows need to be connected

austere thorn
#

This is my full visual script graph if it makes is easier to understand whats going on

crude shell
#

GetPosition And Rotation connect to first SetVariable, then flow that on to the next SetVariable

austere thorn
#

Sorry bad ss

#

This one should be slightly better now

crude shell
#

You will have to make this small change

#

what the greying is telling you is that those nodes never get used

austere thorn
#

Oh I see

crude shell
#

yeah it's good to learn node-based coding approaches too, definitely not a waste of time in your course

#

even if you never use it, it adds to your programming thinking

austere thorn
#

Do you have any idea what that is?

crude shell
#

You don't want 2 update nodes

austere thorn
#

Oh

crude shell
#

you can, not sure what UVS does in that case though tbh, you want to control the execution order, so merge your 2 update paths

austere thorn
#

Ok I'll see what I can do, any idea where to start with it?

crude shell
#

i think UVS will play both, but no promises on which one it plays first, that's why it'd be a something you don't wanna do

#

yeah sure, sec

#

assuming you ordered it that way because that's the order you thought it would run in

austere thorn
#

Yea I did that

crude shell
#

both your branches can then flow on to the same next node

#

i wont say for sure that its reason for your transform issue, but its a step closer to bug-free code, I'll see if anything leads exactly to your issues due to logic

austere thorn
#

Its still doing the same thing, stuck on one side and not moving back. Earlier when I tested it, having either a false or true static value will have it go in its seperate direction

#

Perhaps maybe theres a loop when it reaches one side constantly switching to false and true values?

#

Because it starts out in the middle

crude shell
#

that part will be a logic issue yeah, just taking a look

#

ah ok, i made some assumptions about your code before and didnt read your nodes properly

#

but i see now

#

for starters, try this

#

you want it to set isLeft to false, not true, if >=22

#

so the opposite of its output

#

add negate node

austere thorn
#

Like this?

crude shell
#

yeah

austere thorn
#

When I ran it like this now its going on endlessly to one side

#

Not on the right but now the left

crude shell
#

ah, it checks z but moves in x

ionic tinsel
# austere thorn Not on the right but now the left

because of the fist part of you code you can temporarily remove the if and the 2 Translate nodes then connect straight to the Get Position And Rotation to see if it works(This wont work I also made a assumtion my bad)

crude shell
#

so its z value never reaches that point where it would change the behaviour

crude shell
#

also X7's bit too yeah

#

you can achieve this in a simpler way though

ionic tinsel
#

I could be wrong though

crude shell
#

set a min vec3, and max vec3, ping-pong between the 2 by t

austere thorn
austere thorn
crude shell
#

I may misunderstand your intention. but are you basically trying to make this go back and forth between 2 positions?

austere thorn
#

Yes

crude shell
#

Something like this oughta do

#

Ping Pong is sorta like a 0 to 1 version of a sin function, and you just pass time into that

#

lerp will dance between 2 positions based on that pingpong value

#

feed that to your position

#

it's currently set to a 1 second pingpong in that example

#

in other words

pos = lerp(a, b, pingpong(t, 1))

austere thorn
#

Oh ok let me try that then

#

I see what you mean now

crude shell
#

still, i thought what you had woulda worked too, i'll see if i can figure out why not

austere thorn
#

Alrigth thank you, I'll see if this works

crude shell
#

ah i cant tell from that what the x value actually is, maybe it's miles above 16

austere thorn
#

Where are the two Vector 3 nodes that go into lerp at?

crude shell
#

just type Vector3, they should appear

austere thorn
#

Oh ok thank you, sorry abt that

crude shell
#

s'algud, lemme know when that works, I might have a small suggestion

austere thorn
#

I'm getting an error now:

transform.position assign attempt for 'Slope (4)' is not valid. Input position is { NaN, NaN, NaN }.

ionic tinsel
austere thorn
#

Ok now I don't even see it anymore, what should the values inside the 2 vector 3s be?

ionic tinsel
#

you have to make sure that the X and Y's are the same of what it currently is

#

so click on the gameobject and copy the X and Y and paste them in to the Vector 3 literals

austere thorn
#

Much loves bro thank you so much, I finally got it working ❤️

#

Do you know how to use delta time by the way?

#

Or is it already using it

ionic tinsel
#

if you want delta time just search Time Get Delta Time

austere thorn
#

Oh its built in?

ionic tinsel
#

yeah

austere thorn
#

Oh alright then tahnk you so much again!

ionic tinsel
#

Thanks @crude shell

ionic tinsel
# austere thorn Oh alright then tahnk you so much again!

If you want programmer naming (if you used to C#) you can Go to Edit > Preferences > Visual Scripting untick Human Naming then you can search what it would be like in C# for example Time.deltaTime instead of Time Get Delta Time

crude shell
#

i do that too yeah

#

ok, this will be a mouthful, but bear with me

#

1 prob u will have is what X7 described, where you have to put the exact position values in for the 2 points you want to go between

#

functionally it's fine, but for your level design, it will become a pain very fast

austere thorn
#

Yea unfortunately I did notice that, I have to do this to two more platforms but hopefully my course will have switched to c# before I need to do this in a larger project

crude shell
#

its easier to set like a range, and go from your start position to the min and max of that range

#

that way you never need to know exact positions, just the positions relative to where you've placed it

austere thorn
#

ooh thats smart

crude shell
#

It will be too wordy if i overexplain this, but I think you'll understand if ya read the nodes

#

basically base min/max on current position, then update stays almost exactly how it is, replacing the loose vec3 with the variables you stored instead

#

or if you want to be even more designer'ish, open up 2 variables for transforms, and place the transforms at the a and b points you want to go between, populate your a & b positions with wherever those things are on Start

#

million ways to do it

austere thorn
#

Gotcha

#

I think I'll be able to understand this once I put it in but otherwise this seems very helpful!

crude shell
#

i think too, PingPong is in this shape

#

if you want smoother, use sin instead, but note that it obviously clamps (-1, 1), as opposed to ping pong which is (0, 1)

austere thorn
#

Yea I remmeber when I tried this with Sin, it only went halfway

#

O rnot halfway but you knwo what I mean

crude shell
#

yeah i figured just seeing as you're learning, throw excess examples and you're bound to unlock something

austere thorn
#

lol I think thats true

#

Thank you so much again, I should probably continue this assignment as its due at 11:59 pm and I'm kinda running out of time because I'm leaving the house soon

#

haha

crude shell
#

yep, GL!

violet parrot
#

Why not use a variable moveX +1 to move right and when position > x, moveX turns to -1

And this moveX is the input of transform position onUpdate multiplied by (moveSpeed * deltaTime)

Instead of a bool, just pure if.

And then revert.. when below x moveX turns +1.

crude shell
#

It's good because it fits closely with the initial logic. The main problem was always the condition anyway

violet parrot
#

Sorry not on my computer but there's the graph.

austere thorn
violet parrot
crude shell
#

good idea

austere thorn
#

Good idea

violet parrot
#

Forgot to add moveSpeed * deltaTime so it moves smoothly and you can decide its speed.

violet parrot
#

Here's how you make a moving platform. In this case, +10 x turns to left, and -10 x turns to right.

Using a simple multipler +1 or -1 in the X axis