Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
About Moving?
#4
(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.
Reply


Messages In This Thread
About Moving? - by zero16832 - 27-02-2021, 09:15 AM
RE: About Moving? - by josemendez - 27-02-2021, 09:56 AM
RE: About Moving? - by zero16832 - 27-02-2021, 10:17 AM
RE: About Moving? - by josemendez - 28-02-2021, 07:04 PM
RE: About Moving? - by zero16832 - 01-03-2021, 02:17 AM
RE: About Moving? - by josemendez - 01-03-2021, 01:26 PM
RE: About Moving? - by zero16832 - 02-03-2021, 02:12 AM
RE: About Moving? - by zero16832 - 02-03-2021, 09:46 AM
RE: About Moving? - by josemendez - 02-03-2021, 09:54 AM
RE: About Moving? - by josemendez - 02-03-2021, 11:59 AM
RE: About Moving? - by josemendez - 02-03-2021, 12:23 PM
RE: About Moving? - by josemendez - 02-03-2021, 01:54 PM
RE: About Moving? - by zero16832 - 02-03-2021, 02:42 PM
RE: About Moving? - by josemendez - 02-03-2021, 02:44 PM
RE: About Moving? - by zero16832 - 02-03-2021, 03:11 PM
RE: About Moving? - by zero16832 - 03-03-2021, 02:11 PM
RE: About Moving? - by josemendez - 03-03-2021, 02:28 PM
RE: About Moving? - by zero16832 - 03-03-2021, 02:38 PM
RE: About Moving? - by josemendez - 03-03-2021, 02:44 PM
RE: About Moving? - by zero16832 - 03-03-2021, 02:52 PM
RE: About Moving? - by josemendez - 03-03-2021, 02:53 PM
RE: About Moving? - by zero16832 - 03-03-2021, 03:00 PM
RE: About Moving? - by josemendez - 03-03-2021, 03:05 PM
RE: About Moving? - by zero16832 - 03-03-2021, 03:12 PM
RE: About Moving? - by josemendez - 03-03-2021, 03:18 PM
RE: About Moving? - by zero16832 - 03-03-2021, 03:34 PM
RE: About Moving? - by josemendez - 03-03-2021, 03:44 PM
RE: About Moving? - by zero16832 - 04-03-2021, 09:50 AM
RE: About Moving? - by josemendez - 05-03-2021, 10:38 AM
RE: About Moving? - by zero16832 - 05-03-2021, 02:18 PM
RE: About Moving? - by josemendez - 05-03-2021, 02:39 PM
RE: About Moving? - by zero16832 - 05-03-2021, 03:32 PM
RE: About Moving? - by josemendez - 05-03-2021, 03:41 PM
RE: About Moving? - by the-lander - 01-03-2021, 08:23 AM
RE: About Moving? - by josemendez - 01-03-2021, 09:01 AM