[Need advice] Deployment and technical stuff about character climbing

Hi people,

I’ve been playing with Unity for about 1 and a half week for our tower defense game that will be deployed on mobile device. Being very new to 3D game programming with physics, I struggled quite a bit in these past few days.

For mobs collision detection, I have tried both Rigidbody and Character Controller. And in the end, regardless I know the lack of isGrounded and CollisionFlag feature on Rigidbody, I decided to use it because it’s easier to modify the DragObject script in Unity’s code repository wiki. I’m not sure whether this is the best choice I can do for this project. So I can use some input here.

At this point, there’s something I’d like to make sure for both deployment and technical stuffs.

Deployment:
Say, the game will be as simple as a number of mobs climbing a simple cylinder tower from bottom to top (with varying spawn time, of course). Will it be overkill to have a ragdoll setup on the mobs if I want to deploy the game on iPhone/Android?
If my game is a 3D version of Knight on Rush (3D objects scene, 2d gameplay), would that drain more power from the device compared to those 2D tower defense games? Should I just pay $150 for Sprite Manager 2?

Technical stuffs:
One problem I’m facing right now is how do I properly rotate pitch the mob while climbing depending on the slope it climbs. Other than hardcoding the precise coordinate when it should rotate…
(i.e. if transform.position.y > 5,then transform.rotation.z = 30, and then after passing the slope: if transform.position.y>5.5, then transform.rotation.z = 0)

, is there a more elegant way to do it ? The collider attached to my mobs are now is a box collider. Can a nice climbing physics be achieved with just this 1 simple collider?

I apologize if it’s too long and a bit unclear.

tl;dr version:
I want to make a 3D version of those tower defense games. I’ve done a 2D game programming before on iPhone and Flash. Howeever, I’m new to this kind of 3D game programming (character-animation and physics). Which direction should I go?

Thanks for taking your time to read my post, I appreciate any of your feedbacks.

I think you might want to avoid using rigidbodies for all the enemies if you’re targeting mobiles, unless physics-y behaviour is really needed (say, actually knocking enemies off the tower). Plus, rigidbodies are not really designed to be moved and rotated manually. Instead, they expect to have forces added to them that achieve those effects.

You can use collision detection to find a correct rotation in relation to a slope. See the example code here: Unity - Scripting API: MonoBehaviour.OnCollisionEnter(Collision). It shows you how to get the normal of a surface that a collider is touching, and if you rotate your enemy the same way as this normal, it will match. You will probably want to smooth/interpolate the rotation as the enemy travels from polygon to polygon, otherwise it will snap to new normals instantly. Unity - Scripting API: Quaternion.Slerp will be your friend here. :slight_smile:

Oh, and if you need to rotate along a surface normal if the colliders are not quite touching you can use: Unity - Scripting API: Collider.Raycast. With this you can cast a ray in the direction of the surface you want to rotate along, then get surface normal from the raycast hitinfo.

Thanks for responding Tinus,

However, besides of box/sphere/etc Collider, wouldn’t Collision require a Rigidbody attached to the GameObject?
I tried making a cube and attached this script on it

var accel:float = 1;
var vel:float;

function Update () 
{
	vel = accel*Time.time;
	transform.position.y -= vel*Time.deltaTime;
}

function OnCollisionEnter(collision : Collision) 
{
	print("Collision enter");
}

And it wouldn’t print “Collision enter” when it touches the plane.

So I guess you mean I should not just mess anything related to changing the body dynamics with force?

Oh, forgot about that: Indeed, at least one of the colliders needs a rigidbody attached for collision to register. Sorry about that! You could equip each enemy with a rigidbody with its isKinematic property set to true. That way it does not perform any physics calculations (so you can move it explicitly) but does enable collision.

I tried to add just rigid body and that script above after creating a cube, it still can’t print the message when it made contact with a plane, but certainly will if I uncheck the isKinematic property.

I tried inserting a Start function in the script:

function Start()
{
	rigidbody.isKinematic = true;
	rigidbody.detectCollisions = true;
}

Well… it still went through the plane without collision.

Shame on me for not linking to this: http://unity3d.com/support/documentation/Manual/Physics.html. It lists which setups trigger collisions about halfway down the page.

I have been reading it and played some combination of those.

So basically, if you set it to isKinematic to true, you won’t be able to perform collision detection to mesh collider (in my case, the tower), but you still can do collisions against other non-kinematic Rigidbody collider. Is this right?

Then, in order to keep the computation cost low, my option would be turning the isKinematic to false when I drop the mob. and every other states (running, climbing, etc) have isKinematic set to true.

What would you say?

Thanks for have been responding to my posts Tinus.