make a object shake

As i am new to scripting .In my game i have a boat when my boat hit with the rock i want to make my boat unbalance for few second before coming to its original position.can we make the boat un balance through scripting

Yes, that’s perfectly possible. You’ll want to use the OnCollisionEnter to trigger some kind of animation for the boat. It’s up to you if it’s a animation that’s exported from a 3d graphics program, or you write a script to make it happen in Unity.

I don’t have time to create that much code for someone. Sorry.

In many situations the best way to very realistically unbalance a boat, would be:

Just add an invisible object that has a high mass (say, about the same as the boat or a little less) on the boat, at one side near the top. (If you mean it is a rowboat, add the invisible mass where the rowlocks are; if you mean it is a ship, add the invisible mass on the deck at the middle at one side or even out in the air a little.) Of course to do all this your boat will have to behave physically somewhat like a boat, i.e. it should yaw, tilt and so on.

When you are doing game physics, always ask yourself How would I actually do this, in the real world?. If you had a real boat and you were making a video of the boat, and you wanted a shot where the boat rocked, what exactly would you do to achieve that? i.e. would you push the boat, add an engine, or whatever the actual case might be in the real world. In fact, that’s what you’d do inside the game physics.

I would probably add the invisible heavy object, and have it disappear after a second or so. Another approach is, whatever is “in” your boat (maybe a character) have it move to one side - that too will unbalance the boat.

Don’t forget too that thievery very best way to achieve the boat “hitting a rock” is in fact to have it “hit a rock” ! Simulations (i.e. doing it with “real” physics) are always best in the end. Of course you have to work harder at first to make your objects (boats, whatever) behave in a real-world way.

By all means if this is too hard, make 20 or so different animations of the boat rocking, and choose one randomly!

Hope it helps!