local position not working

i want to add force based on the triggers local position, but it always applies the force in world space, i dont see why this is happening
heres the snippets

if (isclimbing)
    {
        usegravity = false;
        var climbdirection : Vector3 = (hor * right) + (ver * Vector3.up) + -ladderdirection.forward;
        climbdirection *= climbspeed;
        var climbvelocityChange = (climbdirection - velocity);
        climbvelocityChange.x = Mathf.Clamp(climbvelocityChange.x, -maxVelocityChange, maxVelocityChange);
        climbvelocityChange.y = Mathf.Clamp(climbvelocityChange.y, -maxVelocityChange, maxVelocityChange);
        climbvelocityChange.z = Mathf.Clamp(climbvelocityChange.z, -maxVelocityChange, maxVelocityChange);
       
        rigidbody.AddForce(climbvelocityChange, ForceMode.VelocityChange);
function OnTriggerEnter (other : Collider)
{
    if(other.gameObject.tag == "ladder")
    {
        print("climbing ladder");
        isclimbing = true;
        ladderdirection = other.transform.localPosition;
      
    }
}
function OnTriggerExit (other : Collider)
{
    if(other.gameObject.tag == "ladder")
    {
        print("leaving ladder");
        isclimbing = false;
       
    }
}

I don’t understand why you’ve written “ladderdirection = other.transform.localPosition”. What are you intending with this?

What it actually does is get the position of “other” (the thing you collided with) relative to its parent object. It’s not something that’s likely to be useful to some other object colliding with it, unless there’s something special about your setup that I don’t grasp.

If what you intended was to get the position of the other object, relative to this (the one that’s colliding with it), then that would be: ladderdirection = transform.InverseTransformPoint(other.transform.position).

sorry if it wasnt clear but i ve found a solution

function OnTriggerEnter (other : Collider)
{
    if(other.gameObject.tag == "ladder")
    {
        print("climbing ladder");
        isclimbing = true;
        ladderdirection = other.transform.TransformDirection(Vector3.forward);
      
      
    }
}

i needed the negative forward direction of the ladder to force the player to stick to it, but i was always getting the world space vector so i used transformdirection

Ah. You can find the same thing more simply with

ladderdirection = other.transform.forward;

Enjoy,

  • Joe