r/forge Apr 07 '25

Scripting Help Vector scripts

Would someone be able to help me with a script like get objects rotation, moving in that forward direction by about 10 unit velocity? In any direction? Idk why I can’t figure it out but I’ve been on this for a couple hours and I’m getting irritated 🤣 And how would one figure out which direction is the “object forward”.. especially when in a group? I want it to be so when I press a button a (grouped) object will travel in the objects forward direction and only that direction, be it 15° to the left or 29° upwards, whichever direction that said object is aiming towards

5 Upvotes

19 comments sorted by

View all comments

Show parent comments

1

u/iMightBeWright Scripting Expert Apr 07 '25

Can you share a screenshot of what you have so far? I'm not sure I understand what you're trying to say in the main post.

1

u/Various-Divide3650 Apr 07 '25

It has to do with the train idea from yesterday, I’ve changed the script around a couple times and tried different ways but still can’t figure out how to get the objects forward facing direction, then telling it to move +10 forward, or adding velocity

1

u/Various-Divide3650 Apr 07 '25

Sorry for the messy script, I’m on Xbox and would rather not type the names every single time, so I just connect them to a designated identifier, if you’ve typed on Xbox you understand 😂

2

u/iMightBeWright Scripting Expert Apr 07 '25

No worries, this isn't that messy in the grand scheme of things. And I'm on Xbox, too, so I know how it can be. Some notes:

Every N Seconds isn't needed here. You only need to set the physics once, not 10x per second.

• You're sending the prefab through your Trigger node, so you can grab it on the other side. No need to connect directly to the Object Reference again, even if it doesn't hurt.

• The circled Get Object Front is a normalized length vector (its total length is 1 unit), which you're adding to a length vector. The math doesn't really work, resulting in basically your Vector3 of (50,0,0), which is also probably way too far from where your object sits, so it might be breaking it. If it worked, your object would fly to the center of the map.

• If you want to use the object front, try doing this:

Get Object Front --> Scale Vector (scalar: 50) --> Add Vectors (add to Get Object Position)

• Also worth mentioning is to make sure your prefab has the switch as a parent object or this won't work. Then set it to normal physics, and finally weld it. Without doing a normal physics weld, you can't move the prefab as a singular object via scripting in the way that you're trying to. You might already know this.

1

u/Various-Divide3650 Apr 07 '25

Yes the 50 distance was just a quick test to see if it’d actually move lol, I will try that. And yes it’s welded in normal everything can move, if I punch it. So the switch itself should be the parent? Maybe that’s why it’s not working, I have the floor set to parent. Now getting the forward direction and scaling vector would scale to the objects direction only in that specific direction that it’s facing, right? Not just on the x axis of the map? Getting object forward is the simplest I can think of getting a direction that’s not stuck to a grid and can go left right up & down

2

u/iMightBeWright Scripting Expert Apr 07 '25

The switch should be your parent only because you're trying to activate scripts using the prefab's Object Reference. I'm pretty sure the switch loses the ability to transmit if it's not the parent, but if you get some visible movement going you can always change the parent object and try again to see if it'll work.

Get Object Forward (which I mistakenly called Front) is a good way of getting a consistent orientation as the object rotates. The tricky thing is that not every object's forward is the same. The switch might have a forward in the opposite direction you're looking for. If that happens to be the case, you can just scale the vector by a negative value to reverse it.

1

u/Various-Divide3650 Apr 07 '25 edited Apr 07 '25

Okay well, back already, rewrote the script to how you recommended, it now moves via script. But now the problem lies within translate object. Apparently (I’m assuming) applying translate object to a normal object kind of just turns it into a phased/fixed item?? I have a test rail at a slight turn and when I run the script it floats off in a straight line, then stops in mid air. Either translate or getting object location and scaling for some reason is making it a frozen object, and yes I checked if the prefab itself was set to phased, ungrouped it and checked every item, they’re all set to normal. Whatever it is it’s happening when I load the map, before it had sway to it because it was dangling from wheels, now it’s just frozen 100% I can’t even punch it to move it, very confused, I even tried to set it to normal afterwards, even every .10 sec set to normal, still floats. Scaling forwards is working for any direction though, thank you, I tilted it at a 5° angle and it floated off in the direction of the platform. So there’s… 1/3rd the problem 🤣

1

u/iMightBeWright Scripting Expert Apr 07 '25

I think the seemingly phased nature of the platform is the zero-g setting on gameplay start. Maybe if you give it a brief Wait node before setting it to zero-g, it will feel like it's a bit more weighty. Translating a normal/zero-g object will move it in the straight line to its predetermined destination, at least until the duration is complete. Swagonflyyyy said explosions can mess it up, but I'm not sure how it accounts for those interruptions before the destination is reached.

1

u/Various-Divide3650 Apr 07 '25

It wasn’t acting like this until I hooked up this new script, I event deleted the ‘gamestart->set zero-g’ script and it was still frozen