#Platform moving back and forth (Solved)

1 messages · Page 1 of 1 (latest)

potent magnet
#

Shit I never specified I was working with 3D

potent magnet
#

I also forgot I wasn’t asking google, I was asking discord, cause i’ve already tried browsing ^^

fast lake
#

I'm putting as much effort into answering you as you've put into asking your question.
In it's current form we have no idea what you've already tried. Why the things you've tried don't work, what issue you're currently facing etc. etc.

potent magnet
#

First, I didn't know CTRL+C, CTRL+V was that much effort, second, I'm trying to use GDScript to make a 3d platform move back and forth, this is what I've written:

fast lake
#

The thing is, we want to help you learn how to solve issues yourself, rather than being told how to make something.
If you list what you currently have, why that doesn't work, if there are any errors it makes it a lot easier for people to point you in the right direction.
Just saying what you want to do without any kind of context or saying what problems you're running into or struggling with, makes it a lot harder for anyone to point you in the right direction and would require a person helping to start a guessing game.

potent magnet
#

The problem I'm having is the platform just moves forever, never comes back

#

Also if I was wanted to solve this myself with the 4 hours of experience, and a playlist of videos and courses, why do I have access to an entire forum meant for helping me?

#

Or anyone who needs it

fast lake
fast lake
potent magnet
fast lake
#

Because we can still help you move into the right direction? We expect people asking questions to put in effort into both figuring it out and providing enough information for people to actually help.

We're not here to do your work for you.

potent magnet
#

Congrats, this entire thing was a miscommunication -_-

#

I'll just delete this post and never come back here

#

w

rare torrent
#

lmao

fast lake
rare torrent
#

saucy

#

just give your issue and ask for help, if the problem is google away then that's faine

potent magnet
potent magnet
rare torrent
#

you'll have to specify the limits on each axis; the platform position could easily miss an exact vector even with an epsilon

potent magnet
#

Like this?

#

Cause I've also tried that and it went to get the milk

rare torrent
#

what's the position when you print it?

fast lake
#

You're always changing the position by -0.1 on the z axis. The first statement quite frankly shouldn't be there.
What rogan says is correctish however don't compare to a vector3 rather compare specific axis of position. In this case you seem to only really care about the z-axis so only check for that axis, guessing that position is a Vector3 itself position.z

Use an actual if else if flow, now it's just always checking both if statements which is unnecessary since only one can be true at a time.
Last but not least, I'm pretty sure your comparison is incorrect.
If your z axis is greater than -30 even once, it'll always be greater than -30 meaning that it'll always execute that statement.

if position.z <= -30
  move one way
elif position.z >= 30
  move the other way 
rare torrent
#

as long as your platform is axis-aligned you can get away with only comparing position.z

potent magnet
#

Now the platform moves, then stops upon reaching -29.9688205718994

fast lake
#

That's most likely because at that point the first if is true again, tries to move that way, moves back the same amount the frame after giving the illusion of stopping.

You'll need a way to detect if it's reach the endpoint and flip it's movement direct based on that.
Which could be done with a boolean

if position.z <= -30
  boolVar = true
elif position.z >= 30 
  boolVar = false

if boolVar
  move in the positive direction
else
  move in the negative direction
#

This way your move direction is only being decided when one of the key points is hit, otherwise it'll keep moving in the direction it was moving in.

potent magnet
fast lake
potent magnet
#

Oh so this is like batchscript?

fast lake
#

This is like many other programming languages yes.

potent magnet
#

Yeah that just reminded me of batchscript mainly cause I've been using it for 7 years.

#

I hate math but I love variables, that sometimes amazes me.

#

It works

#

Thank you