- Home /
Question by
PlaguedShadow · Aug 19, 2015 at 10:39 PM ·
linerendererslerp
Why aren't slerp and line renderer working together?
In my game the player is suppose to have a chain shoot out and attach to a wall if the raycast hits it. A line renderer that starts at the player and ends at the point where the raycast hit is suppose to slowly appear on screen.
This is my code snippet that controls the chain image:
if (GameObject.Find("Chain Line") == null)
{
Transform tempChain = Instantiate(ChainPrefab) as Transform;
tempChain.name = "Chain Line";
_chainPositions[0] = GameObject.Find("Player").transform.position;
_chainPositions[1] = GameObject.Find("Player").transform.position;
tempChain.GetComponent<LineRenderer>().SetPosition(0, _chainPositions[0]);
tempChain.GetComponent<LineRenderer>().SetPosition(1, _chainPositions[1]);
}
else
{
Transform tempChain = GameObject.Find("Chain Line").transform;
Vector3 tempVector = Vector3.Slerp(GameObject.Find("Player").transform.position, HookshotCollisionPoint, 0.1f - LeftHookshotReloadTime * Time.deltaTime);
_chainPositions[0] = GameObject.Find("Player").transform.position;
_chainPositions[1] = tempVector;
tempChain.GetComponent<LineRenderer>().SetPosition(0, _chainPositions[0]);
tempChain.GetComponent<LineRenderer>().SetPosition(1, _chainPositions[1]);
tempChain.GetComponent<LineRenderer>().renderer.material.mainTextureScale = new Vector2(Mathf.Sqrt(Vector3.SqrMagnitude(_chainPositions[1] - _chainPositions[0]) * Hookshot.ChainIntensity), 1f);
}
What baffles me though is that I have almost the exact same code to make the chain retract and it works just fine. What's going on?
Comment