I want to make my camera move at the ball when the camera has a object in between it, or is in a wall and back when there isnt for example ( atleast when between). How would I go about doing this I have been trying to figure it out XD I have the balls camera at a angle aiming down at it so I assume I need to use local position to make it move at the angle i want (its faceing ( currently at the ball) I was also puzzled on how to figure out what the object is that is hit by a ray (new to rays)
Easy, you use a Physics.Raycast from the player to the camera. If it hits something, then you subtract 1 unit for measure and place your camera there. Code (csharp): var ray : Ray=Ray(target.position, target.position - transform.position); var hit : RaycastHit; if(Physics.Raycast(ray, hit)) transform.position=ray.GetPoint(hit.distance-1);
what is the target in target.position ? I have it like this Code (csharp): var player = GameObject; function Update () { var ray : Ray = Ray(player.Transform.Position, player.Transform.Position - transform.Position); var hit : RaycastHit; if(Physics.Raycast(ray, hit)){ Camera.main.transform.position = ray.GetPoint(hit.distance-1); } } However on line 6 i have problems with the player which will be the ball and the commands to get his position to start the ray and to send it to the camera *script attached to* I tried lots combos of what commands put after the player but doesnt work .....
Does anyone know why the var ray : Ray = Ray(player.Transform.Position, player.Transform.Position - transform.Position); does not work, errors with red mark on left in editor ?