onMouseDown and speed

Hello everyone (I am a beginner so show patience!) :wink:

I made a ship that sails over the sea. The ship object has a steering wheel and a throttle. Both are as RidigBody with a Box Collider. I then detect onMouseEnter to highlight them, then onMouseExit to restore the color.

I also use onMouseUp and onMouseDown to detect those as a Boolean flag.

In the Update function I then check if the mouse is down and the Input.GetAxis to move the RigidBody to change course or speed.

… it works very well and I am pleased … until the ship (experimental very fast one!) reaches a speed over about 12 meters per second. Then, OnMouseOver and OnMouseDown don’t work anymore, as if … the colliders were not following the ship.

So, I checked this community and read that we should rather use Raycast rather than OnMouseOver. Which I did and it works now when the ship sails at high speed. The object changes color but … onMouseDown still isn’t detected so I can’t manoeuvre.
Since the Raycast routine works, I should then detect MouseDown and MouseUp within those codes but … how?

Is it a way to detect the mouse button up, or mouse button down from an “if ()” statement? Thanks in advance.

Cheers,
Michel

Sounds like a call to the Input class. The documented example for GetMouseButtonDown has what I think you need, although this won’t be a test limited to an object like your pre-reaycast stuff. But as you’ve raycast (and I assume have a result) you can check the mouse button and your raycasthit result to see if the player has pressed mouse button actually ON the object.

This is, indeed what I was looking for, my friend! Thank you very much and yes, it works!
I have only started with Unity3D and find it a great tool and … a very good community. I have now to present this feasibility study to my colleagues who are seafarers.

Best regards from Norway,
Michel