I'm trying to make a catpult-based game. I made a model in blender, and imported it. I added a rigidbody to the catapult (so that it can fire a rigidbody projectile.) I also added appropriate mesh colliders. I now have two questions: 1. How do I stop the catapult just falling through my terrain (with terrain or box collider - neither seem to stop it.) 2. How would I rotate the catapult? This is porbably harder as I want to rotate it from one end, rather than from the middle. I think I need to use a hinge joint, but I can't get this to work either.
As for your first part, check to see where your collider actually is. Is it encompassing the catapult properly? Is it connected properly?
For the second, you could use the RotateAround function as follows
var hingePoint : Transform;
var rotateSpeed : int;
function Update() {
// Spin the object around the hinge origin at rotateSpeed degrees/second.
transform.RotateAround (hingePoint.transform,
Vector3.forward,
rotateSpeed * Time.deltaTime);
}
http://unity3d.com/support/documentation/ScriptReference/Transform.RotateAround.html
In my code above, you would place an empty gameobject (containing only a transform) at your hinge point. The arm would then be rotated around that point at your chosen speed.
Alternatively, you could use something like Rigidbody.AddForce or whichever of the functions listed here suits the type of movement you're after best.
I don't have much experience with hinge joints, so I can't speak to that unfortunately, but it sounds like that's pretty much what they're designed for.
The catapult doesn't need a rigidbody, only the arrows do. The most common way to have it pop back a little after it fires would be to play an animation.
For me, the most common cause of a collider falling through the ground is having the bounding area too far below the ground. When two solids are "in" each other, instead of locking them up (like being trapped in a wall) Unity lets them pass through until they are apart. To test, lift it up and see if it falls and stops on the ground.
The most common way of rotating around a certain point is to fix it in the modelling program. Slide all the verts until (0,0,0) is where you want it to rotate around, then reimport. You will probably use a mount point (an empty childed to the object) for the firing position. That will rotate with you just fine, no matter where your center is.
A hinge would also work, but is more for if you want it to flop around sideways as things ram it.