- Home /
FPS's Capsule Collider doesn't work when the FPS is translated.
#pragma strict
private var FPS : GameObject;
function Start () {
FPS = GameObject.Find("FPSController");
}
function Update () {
if (Input.GetMouseButtonDown(0)) {
var buttonName = EventSystems.EventSystem.current.currentSelectedGameObject.name;
var VP : GameObject = GameObject.Find(buttonName); // VP is a viewPoint or Target.
FPS.transform.parent = VP.transform;
Debug.Log(VP);
FPS.transform.localPosition = Vector3(0,0,0);
FPS.transform.localEulerAngles = new Vector3(0,0,0);
FPS.transform.localScale = Vector3(0,0,0);
}
}
The Above code is written to translate the camera form one place to other.. The camera gets translated., but the capsule collider disappears and the camera falls down on the floor.
The Above image is the FPS with collider.
This is without the collider in PlayMode after clicking the VP1 Button(Collider will be present before clicking on the VP button).
Can anyone please let me know what could be the issue here?
What exactly is your code intended to do? Your button should be a delegate, not an event. Your FPS player gets its euler angles set to 0, position to 0,0,0 which is the corner of the map, and you will fall. Then you are setting the entire scale of the object to 0,0,0 which essentially makes it not exist in 3D space. It doesn't destroy it, it is just a size of 0.
Oh yes, the code is written to move the camera to a specified location on button click. VP is a location., when the button is clicked, it finds the Game object with the name VP. And sets the VP object as a parent to the camera. And when the camera is reset , it takes the transformations of the VP object.
And, yes sorry. Scale should be actually 1,1,1 I think that is creating the problem. Will check ASAP and let you know :)
Ok, found that the issue is scale..
But, Unable to set the rotation of the FPS to 0.
When i click on Buttons VP1 or VP2, it takes its previous rotation. Its not working when i tried rotating the FPS in runtime manually.
What is the correct way to reset the camera to Position: 0,0,0 Rotation: 0,0,0 and Scale: 0,0,0 ??
Your answer
Follow this Question
Related Questions
walking inside curved surface 1 Answer
How do you make gravity for the First Person Controller 3 Answers
Affecting FPS controller/Character Motor physics with game object 1 Answer
Attaching First Person Controller to Kinematic Rigidbody 1 Answer
gravity doesnt seem to effect my first person controller....help! 1 Answer