Relative Position Not Constant?
Hi,
As part of a project I'm doing, I need to model a ball with three accelerometers attached to it in Unity. To do this I've created a sphere that can be controlled through keyboard input, and attached three very small cubes to it at different points. I need to collect the positions and angular velocities of all four objects. Collecting the angular velocities require me to attach a rigid body component to each object, which prevents me from making the cubes children of the sphere.
Now because I can't utilize the parent-child relationship I've had to attach a hinge component to each of the three cubes and used them to link the cubes to the sphere. My issue now is this. I want to also collect the location of the cubes with respect to the spheres local coordinates at a given sampling rate. I expected this to be a constant value for every sample since the sphere and cubes move together simultaneously and so, from the perspective of the sphere, the cubes are not changing position at all.
But for some reason I get the positions of the cubes with respect to the spheres local coordinates to be a changing quantity. Why is that? Have I misunderstood something about this situation or is there an issue with my code, given below? Is it because I attached the cubes to the sphere using a hinge and so the cubes are not truly fixed, i.e. have small rotations/movements around the placement point?
I'm truly at a loss here and I appreciate any help you can offer. Even just pointing me in the right direction would be great. Thanks in advance!
// "other" is a GameComponent that refers to the sphere object
// This script is attached to a single cube to transform.position refers to one cube
Vector3 d = transform.position - other.transform.position;
Vector3 rel = Vector3.zero;
rel.x = Vector3.Dot(d, other.transform.right.normalized);
rel.y = Vector3.Dot(d, other.transform.up.normalized);
rel.z = Vector3.Dot(d, other.transform.forward.normalized);
com.Add(rel); // com is a List that holds all the sampled positions
Your answer
Follow this Question
Related Questions
A graph to render sine wave with custom resolution 0 Answers
Is there a way I can make one script for all my buttons in my game? 1 Answer
Add vertex position by it's axis 1 Answer
How to fade in and out two panels in a scene? (c#) 1 Answer
How do I add a simple jump function to this script? 2 Answers