- Home /
Question by
domtate123 · Feb 11, 2013 at 01:55 PM ·
ropeclimbing
Climbing Script
I have a climbing script, it is suppose to enable the character to climb but i cant get it to work... i have tried just about everything but still no climbing.. lol.. if anyone can help me and tell me where im going wrong it would be a massive bonus... The script is Unity script :
public var MoveSpeed :float = 50;
public var jumpSpeed : float = 55;
public var MoveDirection = Vector3.zero;
public var Gravity :float = 45;
public var grounded : boolean = false;
var on: boolean;
var ObjectWall : Transform;
var ClimbSpeed : float = 200;
var NewDirections = Vector3.zero;
var Player : GameObject;
var localPosition : Vector3;
//var HeadBobOn: boolean = false;
//var headBobDistance : Vector3;
//var HeadBobSpeed : float = 3;
//var HeadBobTransform : Transform;
var Movement : boolean = true;
function Start (){
Movement = true;
//HeadBobTransform = transform;
// HeadBobOn = false;
// localPosition = HeadBobTransform.localPosition;
}
function Update () {
if( grounded ){
MoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical"));
MoveDirection = transform.TransformDirection(MoveDirection);
MoveDirection *= MoveSpeed ;
// HeadBobbing ();
}
if( grounded ) {
if(Input.GetKey(KeyCode.Space)){
MoveDirection.y = jumpSpeed;
// HeadBobOn = false;
}
//if(grounded == true){
// HeadBobOn = true;
//}}
if(Input.GetKey(KeyCode.W) || (Input.GetKey(KeyCode.UpArrow)))
{
// HeadBobOn = true;
}
if(Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
{
MoveSpeed = 400;
}
if ( on == true)
{
if(Input.GetKey(KeyCode.C))
{
MoveDirection = new Vector3( 0 , ClimbSpeed , 0);
}
}
if ( on == true){
if(Input.GetKey(KeyCode.V))
{
MoveDirection = new Vector3( 0 , -ClimbSpeed , 0);
}
}
MoveDirection.y -= Gravity * Time.deltaTime;
var Controller = GetComponent(CharacterController);
var Flags = Controller.Move( MoveDirection * Time.deltaTime);
grounded = (Flags & CollisionFlags.CollidedBelow) !=0;
if (on == true){
grounded = (Flags & CollisionFlags.CollidedBelow) !=1;
}
if (on == false){
grounded = (Flags & CollisionFlags.CollidedBelow) !=0;
}
}
}
/*
function HeadBobbing (){
if(HeadBobOn == true){
var BobAmount = Mathf.Min(0.5, Mathf.Abs(Input.GetAxis("Vertical")) + Mathf.Abs(Input.GetAxis("Horizontal")));
var NexPositionX = localPosition.x + headBobDistance.x * Mathf.Sin(Time.time * HeadBobSpeed + Mathf.PI/2);
HeadBobTransform.localPosition.x = (localPosition.x * (1 + BobAmount)) + ( NexPositionX *(BobAmount));
var NexPositionY = localPosition.y + headBobDistance.y * Mathf.Sin(Time.time * HeadBobSpeed + Mathf.PI/2);
HeadBobTransform.localPosition.y = (localPosition.y * (1 - BobAmount)) + ( NexPositionY *(BobAmount));
}
}
*/
function OnTriggerEnter(other : Collider) {
on = true;
if(on == true){
if( other.gameObject.tag == "rope" ){
Debug.LogWarning("You are in the trigger and are ready to climb");
}
else
{
on = false;
}
}
}
function OnTriggerExit(other : Collider) {
on = false;
if(on == false){
if( other.gameObject.tag == "rope" ) {
Debug.LogWarning("You are out of the trigger");
}
else
{
on = true;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Climbing a HingeJoint "rope" 0 Answers
Control the length of a Rope 0 Answers
hook that only keep distance 0 Answers