Hello, i am trying a very simple script, but something seems wrong…
function OnTriggerStay(collision : Collider) {
collision.gameObject.transform.localRotation.y = transform.localRotation.y;
}
Basicly, i want colliding objects to rotate to match the object with the script.
it sort of works, but the Collider doesnt instantly rotate, it slowly rotates over time. I tried adding:
var thisRotation = transform.localRotation.y;
var targetsRotation = collision.gameObject.transform.localRotation.y;
and in the inspector this shows that the target(collider) isnt rotating fast enogh
any suggestions?
PS. the object with this script is just a cube with a Box Collider(is trigger on) and the colliding object has the standard FPSWalker
Are you sure you need localRotation for this rather than transform.rotation?
a friend helped me a little by telling me to set the position as well as the rotation:
private var pos : Transform;
function Start() {
pos = transform.Find("PlayerLocation");
}
function OnTriggerEnter(collision : Collider) {
//collision.gameObject.transform.localRotation.y = transform.localRotation.y;
collision.gameObject.transform.localRotation = transform.localRotation;
collision.gameObject.transform.position.x = pos.position.x;
collision.gameObject.transform.position.z = pos.position.z;
}
it sort of works now, the only problem is that the player “jumps” a little when he hits the collider. this is because his position is being set as soon as he touches it.
is there any way to make the OnTriggerEnter(collision : Collider) only check for object’s centers? intstead of their collider.
PS: Press the A button or the Left arrow key (the onscreen buttons dont work yet)
http://www.sabotender.com/games/dungeon/build1.html
not all the corners work for some reason 
Not really, but there are a couple of other things you could try. One is to put the object’s main collider on the IgnoreRaycast layer, which will prevent it from being detected by the trigger. You could then have a child object with a very small collider located at the centre of the object.
Another possibility is to do the check by removing the trigger and measuring the distance between the object and the target point. You could do this using Vector3.Distance but there is also a more efficient approach. Subtract the transform.position of the trigger/marker object from that of the player:-
var playMarkVec: Vector3 = player.transform.position - marker.transform.position;
Then get the square magnitude of the resulting vector:-
var sqDist: float = playMarkVec.sqrMagnitude;
Then, check this squared distance against the square of the trigger/proximity distance:-
if (sqDist < (proxDistance * proxDistance)) {
...
}
This is much faster than Vector3.Distance because it avoids calculating a square root, which is a CPU-intensive operation.