Hello I have been googling about this issue like crazy and yet I have gotten no where and haven’t been able to get the code working. I am coding in UnityScript using the template made from RAIN when you make a new custom action and I keep getting back a null reference exception error during it. Note I have moved this over to here cause I think I was posting in the wrong area.
The code that works in a regular script (triggered by a button on the UI):
function shoot (){
var layerMask = 1 << 8;
var Rangeofgun : float = 118;
var impactpoint: float;
var fwd = transform.TransformDirection (Vector3.forward);
var ray = new Ray(transform.position, transform.forward);
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, layerMask)){
if (hit.distance <= Rangeofgun){
Debug.Log("It Worked");
}
}
}
This is the code in RAIN with my attempts to alter it:
import RAIN.Action;
import RAIN.Core;
import RAIN.Representation;
@RAINAction
class ShootEnemy extends RAIN.Action.RAINAction
{
public var Rangeofgun2 : Expression;
var Rangeofgun : float = 118;
function Start(ai:RAIN.Core.AI):void
{
super.Start(ai);
}
function Execute(ai:RAIN.Core.AI):ActionResult
{
var ME : AIRig;
var Me = ai.Body.TransformPosition(Vector3.forward);
var layerMask = 1 << 8;
var fwd = ai.Body.transform.TransformDirection (Vector3.forward);
var ray = new Ray(ai.Body.transform.position, ai.WorkingMemory.GetItem("Zombles"));
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, layerMask)){
if (hit.distance <= Rangeofgun){
Debug.Log("It Worked");
}
}
return ActionResult.SUCCESS;
}
function Stop(ai:RAIN.Core.AI):void
{
super.Stop(ai);
}
}
The only options I am really seeing if this doesn’t work is telling the custom action to broadcast to a different script and trigger it that way but that hasn’t really worked ether. Is this possible or am I barking up the wrong tree?
-
This topic was modified 1 year, 3 months ago by
RinAldrin. Reason: Clarification