- Home /
Climbing script - impossible get under the map and turning around
Hi. I want to know what should I write to climbing script to allow my FPS Controller turning around while climbing (of course if he look around for 180 that it doesn't make fall but just view from it) and impossible get under the map - I tried with collider but while climbing it was still possible to "break" this collider and it was still possible to get under the map (which has been made by thing of terrain) by getting down on the labber. So through this I think I do need a code for it but as I'm beginner I don't know what code should it be. As lastly what I need with it is that if I go right or left then it depends what rotation labber has, one time I go right like normal, other time I go instead right that I go left or just forward with other rotation yet. So as previous - I think I do need code which make going right and left with that same rotation where it works like normal.
Here is my code for climbing:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;
namespace FPSSystem
{
public class LadderClimb : MonoBehaviour
{
public Transform chController;
public bool inside = false;
public float heightFactor = 3.4f;
private FirstPersonController FPSController;
void Start()
{
SetInitialReferences();
}
void Update()
{
if (inside == true && Input.GetKey("w"))
{
chController.transform.position += Vector3.up / heightFactor;
}
else
if (inside == true && Input.GetKey("s"))
{
chController.transform.position += Vector3.down / heightFactor;
}
else
if (inside == true && Input.GetKey("a"))
{
chController.transform.position += Vector3.left / heightFactor;
}
else
if (inside == true && Input.GetKey("d"))
{
chController.transform.position += Vector3.right / heightFactor;
}
}
void SetInitialReferences()
{
FPSController = GetComponent<FirstPersonController>();
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Ladder")
{
FPSController.enabled = false;
inside = !inside;
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.tag == "Ladder")
{
FPSController.enabled = true;
inside = !inside;
}
}
}
}
Please so much guys to let me know how to write these 3 commands or how to do that in other hand, if it's possible and easier. I'm beginner and it's kinda hard to find'em all good to work.