I’m trying to store the velocity of a Rigidbody to set the velocity of a different one but the Vector3 variable I’m trying to store it in changes with the updates of the first Rigidbody. Does that make sence? I need the value of a dynamic object at a specific point. Any help would be gratly appreciated. Thanks.
Something like this should work. If it doesn’t work or need any explanation let me know.
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public Rigidbody rb;
public Vector3 savedVelocity;
public Vector3 givenPoint = new Vector3(10,0,0);
public GameObject other;
void Start () {
rb = GetComponent<Rigidbody>();
}
void Update () {
rb.velocity = new Vector3(1,0,0);
if(transform.position.x >= givenPoint.x){
savedVelocity = rb.velocity;
other.GetComponent<Rigidbody>().velocity = savedVelocity;
}
}
}
Thank you but I figured out what was wrong… At some point in experimenting with different behaviors I somehow set my prefab (Rigidbody B) as a child of Rigidbody A. Like when you can’t find your keys because they’re in your hand… I guess its time to start paying attention.