- Home /
Sphere following player with right physics
My player object is a sphere that u can roll around by hitting keys. I want my other sphere object to follow my player at the same speed and with the same physics. The code i have now does follow my player how i want it. However, it does not rotate like my player does. It just slides static towards my player.
My Player (javascript) code:
 #pragma strict
  
 var speed = 25;
 var levelDepth = 15;
  
 function Start () {
  
 }
  
 function FixedUpdate () {
  
         var direction = Vector3(Input.GetAxis("Vertical"), 0, -Input.GetAxis("Horizontal"));
        GetComponent.<Rigidbody>().AddTorque(direction * speed * Time.deltaTime, ForceMode.Acceleration);
    
     if(this.transform.position.y < -levelDepth) {
         this.transform.position = Vector3.zero;
         this.GetComponent.<Rigidbody>().velocity = Vector3.zero;
     }
 }
Object sphere that follows player code:
 #pragma strict
  
 var leader : Transform;
 var follower : Transform;
 var speed : float =5; // The speed of the follower
 function Update(){
     follower.LookAt(leader);
     follower.Translate(speed*Vector3.forward*Time.deltaTime);
 }
  
What is the correct direction towards player code for the physics to actually apply to the follower object as well. How do i get the ball to rotate the exact same way as with the player controller. Help would be very much appreciated :D
Your answer
 
 
             Follow this Question
Related Questions
Constrain rigid body movement to a sphere 3 Answers
Controlling a moving non-kinematic rigidbody along a path 0 Answers
Physics.SphereCastAll with triggers 1 Answer
Why my sphere fly away? 1 Answer
Control and restrict object movement 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                