Forum Discussion
Soundmartell
9 years agoExplorer
How to make the OVRPlayerController Climb a Ladder?
Hello,
Is it any way to make the OVRPlayerController to Climb a Ladder?
I have some script to do that with the Standard First Person Controller but as the OVRPlayerController has not the First Person controller it doesn't work.
I will appreciate any help or support.
Best regards,
Is it any way to make the OVRPlayerController to Climb a Ladder?
I have some script to do that with the Standard First Person Controller but as the OVRPlayerController has not the First Person controller it doesn't work.
I will appreciate any help or support.
Best regards,
8 Replies
Replies have been turned off for this discussion
- cyberealityGrand ChampionThis belongs in the Developer section. Moving the thread. Thanks.
- SoundmartellExplorerSorry about that. Thank you for moving the thread.
Regards. - pjennessRising StarI'd make a trigger volume around the ladder, and when you enter it (or onInside) switch to a ladder control system in your player
Without remembering the proper code:
On the ladder with collider.Test the collider for a player entering
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.htmlonTriggerEnter (Collider thePlayerCollider){
MyCustomController thePlayer =(MyCustomController)getComponent (ofType(MyCustomController));thePlayer.isClimbing = true;
}
inMyCustomControlle (ie you custom code inheritted from OVR controller
}
update(){
if (isClimbing)
{
doClimbMovement();
}
else
{
doUsualMovement();
}
You'll need to add the actual climb anim and logic
Does that make sense.
Its prob what I'd do..but Im sure other people have better ideas.
-P - SoundmartellExplorerpjenness said:
I'd make a trigger volume around the ladder, and when you enter it (or onInside) switch to a ladder control system in your player
Without remembering the proper code:
On the ladder with collider.Test the collider for a player entering
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.htmlonTriggerEnter (Collider thePlayerCollider){
MyCustomController thePlayer =(MyCustomController)getComponent (ofType(MyCustomController));thePlayer.isClimbing = true;
}
inMyCustomControlle (ie you custom code inheritted from OVR controller
}
update(){
if (isClimbing)
{
doClimbMovement();
}
else
{
doUsualMovement();
}
You'll need to add the actual climb anim and logic
Does that make sense.
Its prob what I'd do..but Im sure other people have better ideas.
-P
Thank you. I am new in coding. I will try to figure out how to code a custom controller.
I will appreciate any sample script. I am sorry for being asking for to much.
Regards. - SoundmartellExplorerWell, I created 2 new scripts and added a new function the the OVRPlayerController:Script 1 OVRLadderController.cs attached to the OVRPlayerController.
using UnityEngine;using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
public class OVRLadderController : MonoBehaviour {
public float speed = 5.0f;
private CharacterController controller;
private Vector3 moveDirection = Vector3.zero;
public void _init(){
}
void Start () {
controller = gameObject.GetComponent<CharacterController>();
}
void Update () {
moveDirection = new Vector3(0, Input.GetAxis("Vertical"), 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
controller.Move(moveDirection * Time.deltaTime);
}
}Script 2 OVRLadder.cs Attached to the Ladder Collider.using UnityEngine;
using System.Collections;
public class OVRLadder : MonoBehaviour {
private OVRPlayerController _fps = null;
private OVRLadderController _lc = null;
private bool _activated = false;
private bool _use = false;
private bool _has_controllers = false;
void Start(){
GameObject _go = GameObject.FindGameObjectWithTag("Player");
if (_go != null) {
_fps = _go.GetComponent<OVRPlayerController> ();
_lc = _go.GetComponent<OVRLadderController> ();
if ((_fps == null) || (_lc == null)) {
Debug.LogWarning ("Not found \"LadderController\" or / and \"OVRController\" components");
} else {
_activated = true;
}
}
}
void Update() {
if(_activated && _has_controllers && Input.GetKeyDown(KeyCode.F) || OVRInput.Get(OVRInput.Button.PrimaryThumbstick)){
if(_use){
_use = _lc.enabled = false;
_fps.enabled = true;
_fps._init();
} else {
_fps.enabled = false;
_use = _lc.enabled = true;
_lc._init();
}
}
}
void OnTriggerEnter () {
if (GetComponent<Collider>().tag == "Ladder") {
_has_controllers = true;
}
}
void OnTriggerExit () {
if (GetComponent<Collider> ().tag == "Ladder") {
_has_controllers = false;
if (_activated) {
_use = _lc.enabled = false;
_fps.enabled = true;
_fps._init ();
///We Jump out of the Ladder.
_fps._JumpOutLadder ();
}
}
}
}New function in the OVRPlayerController:
Now the FPS is Climbing Up without any problems but It can't climb down because the FPS keep moving in the Up direction and off course is exiting the trigger.public void _JumpOutLadder(){
MoveThrottle += new Vector3(0, 0, transform.lossyScale.z * LadderOutForce);
}
Is it any way to detect if we are climbing Up or Down and change the FPS moving direction? Maybe using the Camera View Direction or Colliders.
I will appreciate any help.
Regards. - pjennessRising Starmaybe have 2 more trigger volumes, one at the top and one at the bottom.
As you enter the main ladder volume, if it also detects one of those volumes it sets the direction to climb up or down?
These only get checked on entry to the ladder, as it you are alrady on the ladder you dont want them to activate.
Also if you jump and cathc the ladder halfway you want the choice to go up or down to be yours.
Jsut an idea
-P - luismestreHonored GuestHi Soundmartell
I used you scripts to climb a ladder however I get the errors in the screenshots
Can you please help me solving the problem.
Regards
Luis - luismestreHonored GuestHi Soundmartell
Im new to unit and I have used your scripts to climb a ladder, however I get the bellow errors.
Can you please help me solving the problem.
Regards
Luis
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 3 years ago
- 5 months ago