How do I stop this annoying transform from 'snapping'?
Okay, this is a little tough to explain, but here goes:
I have a set of signal generators in an array. Depending on the effect I want, I assign a weight to each, then cycle through them to get a vector that represents the weighted sum of their input. (This lets me, for example, blend a square wave and a sine.) I then assign this value to an object's transform.
First pass
Vector3 total = Vector3.zero;
foreach (SignalGen signal in signalGens) {
total += signal.Activate();
}
transform.position = total;
Trouble is, as you might already have noticed, that this operation will initially teleport the object to whatever total
might be.
Second pass
Adjust the blending code this way:
transform.Translate (total);
And adjust the signal function in this way:
Vector3 point = Generate (amplitude, velocity);
point -= oldPoint;
oldPoint = point;
return point;
This sort of works, but it spazzes out really quickly. At lower frequencies, for example, it increases the signal's amplitude, which is just wrong.
Can some kind soul out there please put me out of my idiotic misery? I know I'm making an elementary mistake somewhere, but I just can't figure it out.
Answer by crisis-sheep · Jul 15, 2017 at 02:25 PM
Well, after that overwhelmingly heartening response, I figured it out myself.
It was pretty simple in the end: I was taking the wrong delta. So instead of this code:
Vector3 point = Generate (amplitude, velocity);
point -= oldPoint;
oldPoint = point;
return point;
I used this code:
Vector3 point = Generate (amplitude, velocity);
Vector3 newPoint = point - oldPoint;
oldPoint = point;
return newPoint;
All sorted.
Your answer
Follow this Question
Related Questions
3D space movement: character stuck at edge in free space 0 Answers
Reading a flowmap with script vs shadergraph 0 Answers
Shopping Cart Movement 0 Answers
3D Survival Shooter Tutorial Movement Code Errors 0 Answers
Sprite mouse movement Unity2D 0 Answers