OnMouse event problem (477557)

Hi Im having a few problems with all OnMouse events. Im working on a vehicule simulator and basically all OnMouseOver events work fine until the platform the first person controller is standing on starts to move (using physics). Then all mouse events stop working until the platform comes to a stop. Strangely enough I have tried using RaycastHit instead of mouseOver and it also has exactly the same problem.

Anyone have any solution? I have looked through the forums but found nothing,

Thanks in advance,

Steve

Hmm… All events stop is a strange thing. Would you mind posting your codes?

Hi Thanks for replying, the code for the Mouse events is as below. But like I said it all works fine until I add force to the moving platform. There are buttons are on the moving platform that have various functions. And even if i replace the OnMouse events with RaycastHit
I get the same problem once the platform starts moving the buttons stop working. Once it stops everything is fine again.

var originalColor;
var highlightMultiply = 4;
var me;
var cursor : Texture2D;
var link : Texture2D;
var normal : Texture2D;
var audioClip:AudioClip;

function Start() {
originalColor = renderer.material.color;
me = GameObject.FindWithTag(“Player”);
}

function OnMouseOver() {
var dist = Vector3.Distance(me.transform.position, transform.position);
if(dist < 5){
renderer.material.color.g = originalColor.ghighlightMultiply;
renderer.material.color.b = originalColor.b
highlightMultiply;
renderer.material.color.r = originalColor.r*highlightMultiply;
Screen.showCursor = false;
cursor = link;
}
}

function OnMouseUp() {

audio.PlayOneShot(audioClip);

}

function OnMouseExit() {
renderer.material.color = originalColor;
Screen.showCursor = true;
cursor = normal;
}

function OnGUI () {
GUI.Label(Rect(Input.mousePosition.x-12, Screen.height - Input.mousePosition.y-10, 100, 100), cursor);
}

do you use animation on the platform instead of just physics? Also is the platform ensured to be able to move so the collider in reality moves too?

otherwise the collider never moves hence raycasts will fail if not done against the original position where the collider basically remains

This is a tough one. I’m thinking the add force physics might mess up the distance between Player and the platform. Print the dist while adding force to check. Perhaps this is not the source of the problem. But this is what I have in mind for now.

Just made a samll test, the size of the ‘button’ seems to make a difference. In the test (package below) both boxes act as buttons and both do the same task (sound a horn and turn on and off a light). But if you move the GUI slider up this adds force to the rig and it starts to move. The small ‘button’ on the left stops working almost immediately while the larger ‘button’ on the right stops working soon after (after around the 40km/h mark)
Both buttons will resume functionality once the train slows down.

PhysicsTestUnity.unitypackage

ftp://183.179.52.11/Public/

I see. I honestly have no idea why. To me, the problem occurred when the track is non linear. Then it starts to get buggy. However, when I drive slowly, It’s working with no error. I also encounter the same problem when the truck is free-fall. But I can’t find the solution.