Forum Discussion
ad2003
11 years agoHonored Guest
Crouch function - how to implement?
Hey there,
most demos have little nice details but are missing a crouch function to make exploring more fun with DK2 -
so I would like to test it in Unity.
Could somebody please tell me how to get a "Crouch" function in js to the OVR Controller?
Is it hard to implement? I tried this code I found on the internet. I see that all scripts in OVR folder are C++ - is it compatible?
It would just need to scale down the OVRPlayer Controller when pressing a key and go back again to the original size, when stop pressing the key.
I found this code - but it doesn't work.
thanks!
AD
most demos have little nice details but are missing a crouch function to make exploring more fun with DK2 -
so I would like to test it in Unity.
Could somebody please tell me how to get a "Crouch" function in js to the OVR Controller?
Is it hard to implement? I tried this code I found on the internet. I see that all scripts in OVR folder are C++ - is it compatible?
It would just need to scale down the OVRPlayer Controller when pressing a key and go back again to the original size, when stop pressing the key.
I found this code - but it doesn't work.
#pragma strict
var walkSpeed : float = 7; //Regular speed
var crouchSpeed : float = 3; //Speed while crouching
var sprintSpeed : float = 13; // Speed while sprinting
private var charMotor : CharacterMotor;
private var charController : CharacterController;
private var theTransform : Transform;
private var charHeight : float; //Initial height
function Start ()
{
charMotor = GetComponent(CharacterMotor);
theTransform = transform;
charController = GetComponent(CharacterController);
charHeight = charController.height;
}
function Update ()
{
var h = charHeight;
var speed = walkSpeed;
if (charController.isGrounded && Input.GetKey("left shift") || Input.GetKey("right shift"))
{
speed = sprintSpeed;
}
if (Input.GetKey("c"))
{
h = charHeight*0.5;
speed = crouchSpeed;
}
charMotor.movement.maxForwardSpeed = speed; // Setting the max speed
var lastHeight = charController.height; //Stand up/crouch smoothly
charController.height = Mathf.Lerp(charController.height, h, 5*Time.deltaTime);
theTransform.position.y += (charController.height-lastHeight)/2; //Fix vertical position
}
thanks!
AD
1 Reply
Replies have been turned off for this discussion
- ad2003Honored Guestmmhh...is this a stupid idea or why does nobody reply? :)
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
- 6 months ago
- 11 months ago