Hi all,
Basically i’m using Kinect and gesture recognition in my game and have a raycast shooting script on the player controlled by a “leftClick” gesture that i call from a script called shadow manager using a boolean called “areWeShooting”.
If areWeShooting is returned true then the player shoots, but because the boolean is marked true the player continually shoots. My assumption is that i should be able to return it as false after the if statement is completed by my heads somewhat cloudy at the minute and i can’t think.
I also suspect it could be that I’m doing this in an Update (checking every frame).
I’m also aware that and “if” checking for boolean is not the easiest way around but given the guidelines i have yo use while using Kinect it’s the only way i could conceive doing it. Sorry for any typos etc, long night / morning.
Script Follows:
#pragma strict
var findGestures : GameObject;
var Range : float = 1000;
var Force : float = 1000;
var Clips : int = 20;
var BulletPerClip : int = 60;
var ReloadTime : float = 3.3;
var Damage : int = 10;
var BulletsLeft : int = 0;
var ShootTimer : float = 0;
var ShootCooler : float = 0.9;
public var ShootAudio: AudioClip;
public var ReloadAudio: AudioClip;
public var hitLayer : LayerMask;
function Start () {
BulletsLeft = BulletPerClip;
}
function Update () {
if( ShootTimer > 0)
{
ShootTimer -= Time.deltaTime;
}
if( ShootTimer < 0)
{
ShootTimer = 0;
}
if(findGestures.GetComponent(ShadowManager).areWeShooting == true){
if( ShootTimer == 0)
{
PlayShootAudio();
RayShoot();
ShootTimer = ShootCooler;
}
}
}
function RayShoot(){
//add an animation for shooting
var Hit: RaycastHit;
var DirectionRay = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);
if (Physics.Raycast(transform.position, DirectionRay, Hit, Range))
{
if (Hit.rigidbody)
{
Hit.rigidbody.AddForceAtPosition(DirectionRay * Force, Hit.point);
Hit.collider.SendMessageUpwards("ApplyDamage" , Damage, SendMessageOptions.DontRequireReceiver);
}
else if(Hit.collider.gameObject.tag == 'Enemy')
{
Hit.collider.GetComponent(EnemyHealth).takeDamage();
print("StepONE");
}
}
BulletsLeft --;
if(BulletsLeft < 0)
{
BulletsLeft = 0;
}
if(BulletsLeft == 0)
{
Reload();
}
}
function Reload(){
PlayReloadAudio();
//Play animation for reload
yield WaitForSeconds(ReloadTime);
if (Clips > 0)
{
BulletsLeft = BulletPerClip;
}
}
function PlayShootAudio(){
audio.PlayOneShot (ShootAudio);
}
function PlayReloadAudio(){
audio.PlayOneShot (ReloadAudio);
}
The ShadowManager script is quite long and references a lot of things that aren’t applicable but i know to call a gesture I declare the boolean:
public bool areWeShooting = false;
and then i call the gesture and mark the bool true if we leftClick
if (isGestureActive(“leftClick”,0) == true)
{
areWeShooting = true;
}
I’m not sure if i have to call another gesture like “idle” and then mark areWeShooting as false or i can call a single instance of leftClick and then re-mark the bool as false afterwards.
Sorry if i’ve not made myself clear with the extra info
Any help is much appreciated,
Kev