- Home /
Help with function code, passing Vector3 info
I wrote a function that passes a few vectors and I want to return a new vector3 position. Multiple Vector3 positions I am sending are coming back with the wrong position before and after the function is called. Also the functions return Vector3 always comes back 0,0,0. Any help is greatly appreciated guys!
p.s. Functions are still a little fresh for me!
//FUNCTION
Vector3 NextPos(GameObject objlerp, float lerp, GameObject player, GameObject planetm){
Debug.Log(objlerp.transform.position);
Vector3 two = Vector3.Lerp(instPoint.transform.position, objlerp.transform.position, lerp);
float distancefromp = Vector3.Distance(planet.transform.position, two);
float gravitym = planet.rigidbody.mass / (distancefromp * distancefromp);
float gravitypullm = distancefromp - gravitym;
Vector3 nextpos = Vector3.Lerp(planet.transform.position, two, gravitypull);
return nextpos;
}
// INPUT IN UPDATE FUNCTION
if(Input.GetKeyDown(KeyCode.S)){
Debug.Log(p2lerp.transform.position);
p4.transform.position = NextPos(p2lerp, 0.7f, instPoint, planet);
}
Okay, havent had much feedback but I didnt realize a child will return the position of the parent or what not in the inspector. I used racast.point to deter$$anonymous$$e the position I debugged above is correct now I am going to debug everything in the function until I find the culprit!
Answer by aronatvw · Mar 06, 2014 at 03:37 AM
I had to declare a new vector first before returning it as a position. I rather do this in one step if someone knows how that would be cool anyways here is the code.
if(Input.GetKeyDown(KeyCode.S)){
Vector3 newp4 = NextPos(p2lerp, 0.7f, instPoint, planet);
p4.transform.position = newp4;
}
Your answer
Follow this Question
Related Questions
Expanding functions 1 Answer
Help with a simple function. 1 Answer
function error 1 Answer
is it possible to use a rotation on a Vector3? 3 Answers
what is the problem of this code ? 2 Answers