- Home /
Fps Ladder script...
Hello,I am currently just simply using the standard fps controller.I am not a coder(even though I need to be)So I was wondering If I could get a simple ladder script that would move my fps controller up the y axis once I touch(collide) the ladder to work with a standard fps controller. Any feedback is appreciated, ;)
Answer by uhahaha · Dec 12, 2010 at 03:22 AM
(1) Attach a box collider in addition to a mesh collider to your ladder object (name it "ladder"). In the Inspecter check the "Is Trigger" property in the Box Collider. It will be used as a trigger, and the following code uses this property. The Mesh Collider prevents the First Person Controller from falling through the ladder.
(2) Create a javascript and copy&paste the code below, and attach the script to the First Person Controller.
(3) I set the slope limit to 85, but you can change that howver you wish.
function OnTriggerEnter (other : Collider) { if(other.gameObject.name == "ladder") { transform.GetComponent(CharacterController).slopeLimit = 85; transform.GetComponent("CharacterMotor").sliding.enabled = false; } }
function OnTriggerExit (other : Collider)
{
if(other.gameObject.name == "ladder")
{
print("leaving ladder");
transform.GetComponent(CharacterController).slopeLimit = 45;
transform.GetComponent("CharacterMotor").sliding.enabled = true;
}
}
You could use OnControllerColliderHit etc instead of OnTrigger functions- it's up to you. This is just one way I came up off the top of my head, and I can imagine various other methods. Hope it helps.
I tried to convert this to .cs, I get
Assets/scripts/ClimbLadder.cs(14,54): error CS1525: Unexpected symbol )' Assets/scripts/ClimbLadder.cs(22,54): error CS1525: Unexpected symbol
)'
transform.GetComponent<"Character$$anonymous$$otor">().sliding.enabled = true;
using UnityEngine; using System.Collections;
public class ClimbLadder : $$anonymous$$onoBehaviour { //climb_ladder.cs
void OnTriggerEnter ( Collider other ){ if(other.gameObject.name == "ladder") { transform.GetComponent().slopeLimit = 85; //this is line 14 transform.GetComponent<"Character$$anonymous$$otor">().sliding.enabled = false; } }
void OnTriggerExit ( Collider other ){
if(other.gameObject.name == "ladder")
{
print("leaving ladder");
transform.GetComponent<CharacterController>().slopeLimit = 45;
transform.GetComponent<"Character$$anonymous$$otor">().sliding.enabled = true;//line 22
}
}
}
Your answer
Follow this Question
Related Questions
How to move target when it collides with a bullet 1 Answer
FPS RIGIDBODY PROBLEM 1 Answer
FPS Ladder Script Help(C#) 1 Answer
Object falling through terrain with script 2 Answers
Places to better learn Unity Scripts 1 Answer