Does anyone know of any documentation about this effect?
Maybe someone know of any existing documentation on this effect of a character model following the players movements? Ive found i few videos of people exploring this mechanic, but it literally lik 2-3 videos that i was able to find. And non of the creators shared any documentation about, i really need to achieve this effect, but i am not even an amateur in programming, and with no documentation its hard to understand where to even begin. If anyone knows more about or has even tried to achieve something like this, maybe then they could share some documentation or some source code used for it? Any information is highly appreciated. <3
Answer by streeetwalker · Dec 12, 2020 at 07:34 PM
It would not be too difficult to do something like that, but if you are not a programmer it will be because you have to understand how you are going to relate the motion of one object to another.
In the example you show it is complicated by the fact that the hands and arms are probably child objects of the figure, so you would need to convert their local motion to values you could use on objects that are not children.
The basic idea is just to move one object based on the motion of another
You can set up a simple example controlling one game object - put 2 cubes into a scene, name them cube1 and cube2, spread them apart, and add this script to cube1. Place cube1 at the world origin, and don't rotate the cubes for this example - we want them aligned to the world x, y, and z axes. Also don't resize them.
create a new script named MoveCube and place it on cube1 as a script component. Be sure to match the name exactly upper and lower case.
public class MoveCube {
// assumes you are working in 3D
// drag the cube2 to this field in the inspector of this script
public Transform cube2;
public speed = 10f;
private Vector3 cube2Offset;
void Start(){
// save the relative difference in the cubes' positions for later
cube2Offset = cube2.transform.position - transform.position;
}
void Update((){
//move cube1 using the mouse up and
//down or use arrow up and down keys
float translateZ = Input.GetAxis("Vertical") * speed * Time.deltaTime;
transform.Translate( 0, 0, translateZ );
// here is where we control cube2
// I've put this in its own function just so
// we can keep update simple
MoveCube2(transform.position.x, transform.position.z);
}
private void MoveCube2( float x, float z ){
// here we can manipulate x and z how ever we want
// in this example, the farther away cube1 moves from world center
// along the z axis, the closer cube2 will move to cube1
// while paralleling cube1's motion on z
//move closer to cube1 on the x axis the farther
// cube1 moves on z until they touch
// what we do to x and z here we can call "transform functions"
x += cube2Offset.x - (cube2Offset.x * Mathf.Abs(z)/cube2Offset.x);
float signX = Mathf.Sign( x );
if( Mathf.Abs(x ) < 1 ){ // keep them at least 1 meter apart
x = 1 * signX;
}
// parallel cube 1 on the z axis
z += cubeOffset.z;
cube2.transform.position = new Vector3(x, 0, z) ;
}
}
That's it. You can play around with different starting positions for the cubes, and different statements to change the values of x and z in the MoveCube2 function.
Note that I called the changes we make to x an z "transform functions" if we just leave those to be:
x += cubeOffset.x;
z += cubeOffset.z;
Then cube2 will just move parallel with cube1 and maintain the same relative distance it had from the start. By altering the x and z transform functions, we can get cube2 to move in different ways as cube 1 moves.
I haven't tested this, but I don't think there are any errors in the code and I believe the math is solid for the described behavior.
Your answer
Follow this Question
Related Questions
VR body IK mimicking problem (searching for help). 0 Answers
Oculus Go & Unity: Microphone Real-time Playback 1 Answer
Tracking not working for both controllers at the same time on Oculus Quest build 7.0 6 Answers
Dots VR project.,need help in Dots VR project 1 Answer
[VR][VIVE] allow rotation only ? 4 Answers