Posts: 23
Threads: 4
Joined: Feb 2021
Reputation:
0
According to the example you provided, I wrote a demo that uses the mouse to move. At first, the demo is normal, but the later movement slowly turns into the opposite direction. Why?
if (Input.GetMouseButton(0))
{
direction += moveDirection* moveSpeed;
softbody.AddForce(direction.normalized * moveSpeed, ForceMode.Acceleration);
}
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(27-02-2021, 09:15 AM)zero16832 Wrote: According to the example you provided, I wrote a demo that uses the mouse to move. At first, the demo is normal, but the later movement slowly turns into the opposite direction. Why?
if (Input.GetMouseButton(0))
{
direction += moveDirection* moveSpeed;
softbody.AddForce(direction.normalized * moveSpeed, ForceMode.Acceleration);
}
It’s hard to tell just by looking at that code. However, the code doesn’t make a lot of sense to me:
You’re adding moveDirection * moveSpeed to direction, but you’re then normalizing it. This will make direction a vector of unit length, but then you multiply it by moveSpeed a second time.
No need to do the first multiplication if you’re normalizing the vector afterwards, as it will be unit length anyways. I don’t see anything that would reverse the movement direction though. Can you post the full code?
Posts: 23
Threads: 4
Joined: Feb 2021
Reputation:
0
27-02-2021, 10:17 AM
(This post was last modified: 27-02-2021, 10:51 AM by zero16832.)
It's normal to use "addforce" in "editor" to move, but in "mobile", it's normal at the beginning, and then "addforce" gradually becomes invalid for the second or third time. Sometimes it moves in the opposite direction, sometimes it doesn't move directly. I make sure that the direction I apply to "softbody" is the same, but I feel affected by an inexplicable reverse force.
I found the [font=宋体, monospace]solver.velocities [/font]it would go back to zero automatically?
and can i use change [font=宋体, monospace]velocities.x to make the item move?[/font]
(27-02-2021, 09:56 AM)josemendez Wrote: It’s hard to tell just by looking at that code. However, the code doesn’t make a lot of sense to me:
You’re adding moveDirection * moveSpeed to direction, but you’re then normalizing it. This will make direction a vector of unit length, but then you multiply it by moveSpeed a second time.
No need to do the first multiplication if you’re normalizing the vector afterwards, as it will be unit length anyways. I don’t see anything that would reverse the movement direction though. Can you post the full code?
the code here,i just change some code with the obi demo.
SoftbodyController.cs (Size: 6.25 KB / Downloads: 8)
code here
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
28-02-2021, 07:04 PM
(This post was last modified: 28-02-2021, 07:06 PM by josemendez.)
(27-02-2021, 10:17 AM)zero16832 Wrote: It's normal to use "addforce" in "editor" to move, but in "mobile", it's normal at the beginning, and then "addforce" gradually becomes invalid for the second or third time. Sometimes it moves in the opposite direction, sometimes it doesn't move directly. I make sure that the direction I apply to "softbody" is the same, but I feel affected by an inexplicable reverse force.
I found the [font=宋体, monospace]solver.velocities [/font]it would go back to zero automatically?
and can i use change [font=宋体, monospace]velocities.x to make the item move?[/font]
the code here,i just change some code with the obi demo.
code here
Hi,
Just tested your code (commented out the GameManager references/lines, as I don't have that script) and it works fine for me. The softbody always moves in the same direction. What are you using as your referenceFrame? The script moves the softbody in the direction of referenceFrame's axis, so only possible explanation is that the frame is rotating/pointing in some unexpected direction. The original script uses this to make the controls relative to the camera frame.
On a side note, this part of the script:
Code: for (int i = 0; i < softbody.solverIndices.Length; i++)
{
float xVelocitie = softbody.solver.velocities[i].x;
xVelocitie += 0.05f;
if (xVelocitie > -2)
{
xVelocitie = -2;
}
//softbody.solver.velocities[i] = new Vector4(xVelocitie, softbody.solver.velocities[i].y, softbody.solver.velocities[i].z, softbody.solver.velocities[i].w);
Debug.Log("<color=green>velocities:</color>" + softbody.solver.velocities[i]);
}
Looks wrong, you're iterating over solver.velocities, but using the length of the softbody indices array. This will result in incorrect results at best, or an out of bounds access at worst. I think what you want is:
Code: for (int i = 0; i < softbody.solverIndices.Length; i++)
{
float xVelocitie = softbody.solver.velocities[softbody.solverIndices[i]].x;
// ....etc
}
Quote:I found the [font=宋体, monospace]solver.velocities [/font]it would go back to zero automatically?
Your script is not setting velocities at any point, you're just logging their value. It never actually writes back the modified values:
Code: // copy the velocity on the x axis into a variable:
float xVelocitie = softbody.solver.velocities[i].x;
// increment the variable, then set it to -2 if it's larger than -2
xVelocitie += 0.05f;
if (xVelocitie > -2)
{
xVelocitie = -2;
}
// xVelocitie is not written back to softbody.solver.velocities[i]
Since velocities are automatically calculated by the physics engine, they will reach zero eventually in absence of any external modifications.
Posts: 23
Threads: 4
Joined: Feb 2021
Reputation:
0
YEAH I USE THIS SCRIPT IN WINDOW OR UNITY EDITOR IT WELL,BUT IN ANDROID OR IOS,IT HAVE SOME problem,When click on the screen and then release the click, and click the second time, the direction of movement changes. I don't know what's going on。It felt like there was an inexplicable reverse force
Posts: 21
Threads: 5
Joined: Aug 2020
Reputation:
0
Hey! I'm not the one with this bug!
Same problem here:
http://obi.virtualmethodstudio.com/forum...-2468.html
Everything is ok in on PC but on Android the further a softbody goes from the zero point in unity the more it's forced to move there by itself. It's like my softbodies are connected with something with a rubber string.
Every new project I've started using different Unity version has this bug.
Here are some videos:
https://www.youtube.com/watch?v=f1ALZPc1...=youtu.be4
https://drive.google.com/drive/folders/1...sp=sharing
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(01-03-2021, 08:23 AM)the-lander Wrote: Hey! I'm not the one with this bug!
Same problem here:
http://obi.virtualmethodstudio.com/forum...-2468.html
Everything is ok in on PC but on Android the further a softbody goes from the zero point in unity the more it's forced to move there by itself. It's like my softbodies are connected with something with a rubber string.
Every new project I've started using different Unity version has this bug.
Here are some videos:
https://www.youtube.com/watch?v=f1ALZPc1...=youtu.be4
https://drive.google.com/drive/folders/1...sp=sharing
Could reproduce this on Android, but not on iOS. I suspect OP's issue and yours are completely unrelated. Will get back once I have more information.
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
01-03-2021, 01:26 PM
(This post was last modified: 01-03-2021, 01:27 PM by josemendez.)
(01-03-2021, 02:17 AM)zero16832 Wrote: YEAH I USE THIS SCRIPT IN WINDOW OR UNITY EDITOR IT WELL,BUT IN ANDROID OR IOS,IT HAVE SOME problem,When click on the screen and then release the click, and click the second time, the direction of movement changes. I don't know what's going on。It felt like there was an inexplicable reverse force
I'm still unable to see any differences in behavior when building to iOS/Android. Another user has reported a similar problem (see above), but their project had different circumstances, related to floating point precision issues.
Would it be possible to share your project with us so that we can take a look at scene setup and other settings? send it to support(at)virtualmethodstudio.com.
Posts: 23
Threads: 4
Joined: Feb 2021
Reputation:
0
(01-03-2021, 01:26 PM)josemendez Wrote: I'm still unable to see any differences in behavior when building to iOS/Android. Another user has reported a similar problem (see above), but their project had different circumstances, related to floating point precision issues.
Would it be possible to share your project with us so that we can take a look at scene setup and other settings? send it to support(at)virtualmethodstudio.com. The Demo Is send your,thx for your help
Posts: 23
Threads: 4
Joined: Feb 2021
Reputation:
0
(01-03-2021, 01:26 PM)josemendez Wrote: I'm still unable to see any differences in behavior when building to iOS/Android. Another user has reported a similar problem (see above), but their project had different circumstances, related to floating point precision issues.
Would it be possible to share your project with us so that we can take a look at scene setup and other settings? send it to support(at)virtualmethodstudio.com. Have you come back to that problem?
|