I have a sword (using the suggestion i got from my previous thread) that raycasts, to find the point of collision. HOWEVER, it only checks in the global upward direction, rather than turning to face whatever direction my sword is oriented. Here is my code so far, just to see if i am indeed getting a registered collision.
#pragma strict
var contact : boolean;
function Start () {
}
function Update () {
var hit : RaycastHit;
if(Physics.Raycast(transform.position, transform.up, hit, 10))
{
contact = true;
}
else
{
contact = false;
}
}
most of this seems self explanatory, but i just need to know how to get the local “up” rather than the global.
It didn’t work… here is my current code now: (I am using debug.drawRay to visualize it)
#pragma strict
var contact : boolean;
var up : Vector3;
function Start () {
}
function Update () {
var hit : RaycastHit;
up = transform.TransformDirection(Vector3.up);
if(Physics.Raycast(transform.position, up, hit, 10))
{
contact = true;
}
Debug.DrawRay (transform.position, up, Color.green);
}
ok, so, It didn’t work, BUT using trasnformDirection, I managed to achieve my goal.
here is the code, for anyone who wants it:
#pragma strict
var contact : boolean;
var up : Vector3;
function Start () {
}
function Update () {
var hit : RaycastHit;
up = transform.TransformDirection(1,0,0);
if(Physics.Raycast(transform.position, up, hit, 10))
{
contact = true;
}
Debug.DrawRay (transform.position, up, Color.green);
}