Hi guys,
we’re making a flying 3rd person level in a game and want the character to fly on 3 different levels (just above rooftops, in clouds, in space). So far we’re just using the standard 3rd person controller scripts from the 3rd person platform game on the unity site.
Then to raise up and down between the 2 levels we’re using keypresses to raise the position of the character then increase the height of the collider to keep it at that height, so effectively its standing on a massive invisible capsule - not a great way to do it! Can someone suggest a better way we can do this please!
Cheers,
Will

HHHMMM, couldn’t you specify a range on the Y and constantly check that on Update?
In other words, as you are flying along, you check the characters Y in relation to the limit and if below that limit then add force to push it above it.
Make sense?
HTH,
– Clint
Really the best way would be to write a script that adds flying behavior to the character controller, or modify the 3rd person walker script to do that.
Create an empty object with a box collider and put it in the desired levels of highness, make sure your character moves along with it.
If the collision is giving you troubles, then create a layer for the character and the invisible platform only.
Anyways, i had rather create another script for the flying character, it’s easy to do so try it.
Putting colliders on separate layers will not cause them to not collide. Use Physics.IgnoreCollision() instead.
Here is a handy script I have used before. It makes the object it is attached to not collide with any objects that have the specified tag.
var tagToIgnore = "";
var layerColliders = Array();
layerColliders = GameObject.FindGameObjectsWithTag (tagToIgnore);
for (var layerCollider in layerColliders)
{
if(layerCollider.collider gameObject.collider != layerCollider.collider) Physics.IgnoreCollision(collider, layerCollider.collider);
}
That might not be exactly what you want. What I have used it for is having all objects with a certain tag carry that script and not collide with each other. But it might help you, too.
Guys,
thanks for all your replies, we’ve opted for the rigidbody add relative forces idea, and have come up with this simple script so far -
var theplayer : GameObject;
function Update(){
var playerPos = theplayer.transform.position;
if(playerPos.y <=30){
rigidbody.AddRelativeForce(0, 8, 0);
}
}
However, this produces a bungey rope style effect, and doesnt keep him floating, how can I best specify a range for him, rather than simply check hes fallen below y:30?
Any help much appreciated,
Cheers,
Will
In the past I’ve had great success by looking a bit ahead… So you check would become sth like:
if (transform.position.y + rigidbody.velocity.y * timeFudgeFactor < 30)
So basically, if he’s gonna be below 30 meters in one sec, start adding forces now. You need to tweak the timeFudgeFactor to get the right feel.