Help Change obi rope attachment target realtime with script - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Help Change obi rope attachment target realtime with script (/thread-4026.html) |
Change obi rope attachment target realtime with script - Adammm - 06-10-2023 Hey! I was trying to change obi rope attachment the other day with script, and I couldn't make it happen. Whenever I do it manually in the inspector while playing the rope snaps to the new target position. But if I do it with script (just change the attachment script target to new transform), it changes the target but won't change the position nor do anything. Can somebody help me with this and if fix the issue? RE: Change obi rope attachment target realtime with script - josemendez - 09-10-2023 (06-10-2023, 03:26 PM)Adammm Wrote: Hey! I was trying to change obi rope attachment the other day with script, and I couldn't make it happen. Whenever I do it manually in the inspector while playing the rope snaps to the new target position. Hi, Attachments should not snap to a new position when changing their target, there's nothing in their code that enforces this. By default they just attach particles at their current position relative to the target: http://obi.virtualmethodstudio.com/manual/6.3/attachments.html Quote:It's important to realize that attachments do not move the particle group to the position of the target object, nor the target object to the position of the particle group. Moving the particle group to the target's position would collapse all particles into a single point, and would result in a kickback effect once the particles spring back to their original positions. Moving the target could cause a whole palette of issues depending on your game logic. (06-10-2023, 03:26 PM)Adammm Wrote: But if I do it with script (just change the attachment script target to new transform), it changes the target but won't change the position nor do anything. If you want to change the position of the particles before attaching them, you need to do that manually. See: http://obi.virtualmethodstudio.com/manual/6.3/scriptingattachments.html kind regards. RE: Change obi rope attachment target realtime with script - Adammm - 09-10-2023 My ropes are already connected to the player hands, like I said before whenever I change the target with script,nothing happens. But if I do it manually (like in the video) then it will snap to the new position. What I need is exactly like in the video (snapping to new position) but with script. https://streamable.com/ao36e0 RE: Change obi rope attachment target realtime with script - josemendez - 10-10-2023 (09-10-2023, 05:27 PM)Adammm Wrote: My ropes are already connected to the player hands, like I said before whenever I change the target with script,nothing happens. As I said what will happen is that the rope will be re-connected to the new target but won't cause the rope to snap to a new position, it will keep its position relative to the previous target. This is explained in the manual: Quote:It's important to realize that attachments do not move the particle group to the position of the target object, nor the target object to the position of the particle group. Moving the particle group to the target's position would collapse all particles into a single point, and would result in a kickback effect once the particles spring back to their original positions. Moving the target could cause a whole palette of issues depending on your game logic. (09-10-2023, 05:27 PM)Adammm Wrote: But if I do it manually (like in the video) then it will snap to the new position. What I need is exactly like in the video (snapping to new position) but with script. Quoting the manual: "If you want particles attached at a specific position other than their position at the time of creating the attachment, you can set their position at runtime before creating the attachment: see scripting particles." In other words, you just need to set the position of the attached particles before changing the attachment target via script. This is easy to do: the following code will move the particle to the same local space position in the new target object, just like it happens in the editor: Code: // get the index of the attached particle in the rope and the solver: The only tricky bit is to convert from the target's local space to the solver's local space and vice-versa, using Unity's TransformPoint /InverseTransformPoint. kind regards, |