I created a double hung window in 3ds max with animations of the bottom sash opening and closing. The idea is that you click on the sash and it opens, click on it again and it closes. I made this partially work. The parent object (“window_doub_hung”) contains the animations, the collider, and the script as seen. I click anywhere on the window (green collider) and the lower sash (part with glass) opens, click again and it closes.
The problem is this: I want my characters to be able to jump through the window when it is open, and not when it is closed. I need a collider to be attached to that lower sash only, so that it moves out of the way when the window is open (allowing jump-through), and back when it closes.
I think I need to make a collider for the lower sash, while keeping the script as part of the parent object since it contains the animations. I don’t know how to make a collider attached to a child object talk to a script attached to a parent object.
Thanks.
From the screenshot, it looks as though the sash is a child object. Does this child object actually move its anchor point in the animation or does the mesh move relative to the anchor?
If the anchor moves, you might just be able to add a BoxCollider to the child object. Otherwise, you’ll have to create a separate collider object and move it from a script. To answer your original question, though, you can navigate an object hierarchy using the transforms. The Transform class has a variable called parent and also a Find function that retrieves a child object by name.
Yes, simple enough. Now my box collider / trigger causes the lower sash to go up and down, anchor point and all, with a new box collider I attached to it and I’m in business.
Next challenge: BOTH the upper and lower sash are animated. How do I set up TWO Box Collider triggers, one to trigger the lower sash, and one to trigger the upper sash. Ideally, these triggers will move with the sash.
So there’s two issues: the script being able to tell which of two triggers is being triggered, and the script moving the trigger along with the window sash. If the trigger BoxCollider is a child of the sash_bot, there’s also the issue of how it communicates with the script which is a child of window_doub_hung.
Got it.
Script attached to window_double_hung “OpenClose.js”:
var botOpen=0;
var topOpen=0;
function openBottom()
{
if (!botOpen)
{
animation.CrossFade("open_bot");
botOpen = 1;
}
else
{
animation.CrossFade("close_bot");
botOpen = 0;
}
}
function openTop()
{
if (!topOpen)
{
animation.CrossFade("open_top");
topOpen = 1;
}
else
{
animation.CrossFade("close_top");
topOpen = 0;
}
}
I gave sash_bot a BoxCollider trigger, and this script:
function OnMouseDown()
{
window = GameObject.Find("window_doub_hung");
var other = window.GetComponent("OpenClose");
other.openBottom ();
}
Similar script for sash_top.
The only thing left was to attach colliders so that my character couldn’t go through a closed window. It wouldn’t let me give the sash a second BoxCollider so I assigned it to the glass_bot child object.
Hmm… I think I’m starting to get it![/code]