Character Controller wall ricochet or bounce

RE-EDIT
Taking some much needed advice and simplifying.

All I’d like to do is see if I can have a character gameobject, which has a cube mesh character controller attached, can bounce or reflect it’s velocity when it hits a wall while moving instead of any kind of collider, just using collisionFlags.

I know of rigidbody physics and of using raycasting from sides while moving to detect sides but I don’t think they’ll work well with the controls on the gameobject.

My variables, function Update and calling the controller:

#pragma strict


private var moveDirection : Vector3 = Vector3.zero;

var gravity : float = 20.0;
var flightSpeed : float = 1.0;
var velocity : Vector3;
var curVelocity : Vector3;
var grounded : boolean = false;
var touchingWall : boolean = false;
var touchingCeiling : boolean = false;

static var chargeTime : float = 0;
static var chargeAmount = 0;
static var chargeLimit = 4;
static var isHolding : boolean = false;


function Update() {
	
        var controller : CharacterController = GetComponent(CharacterController);	
	collisionFlags = controller.Move(moveDirection);

Within the function update I check for a raycast hit on the character gameobject. Then If raycast returns true set isHolding to true which will bring up directional arrow cubes. If collided with one send the game object in that direction. Only the code for sliding over the Upper Left box is shown for simplicity.

	var hit : RaycastHit;
	for (var touch in Input.touches)
	{	
		if (touch.phase==TouchPhase.Stationary)
		{
			ray = Camera.main.ScreenPointToRay (Vector3(touch.position.x, touch.position.y, 0));
			if (Physics.Raycast (ray, hit)  hit.collider.gameObject.tag=="Player")
			{ 
				moveDirection = Vector3(0, 0, 0);
				if(chargeAmount<3)
				{
					isHolding=true;
				}else if (chargeAmount==3  touch.phase==TouchPhase.Ended)
				{
					isHolding=false;
				}
			}
	 	}	
		if(touch.phase==TouchPhase.Moved)
		{
			ray = Camera.main.ScreenPointToRay (Vector3(touch.position.x,touch.position.y, 0));
	 		if (Physics.Raycast (ray,hit)&hit.collider.gameObject.tag=="UL")
			{	
	 	 		if(isHolding==true)
	 	 		{	
	 	 			chargeTime=0;
	 	 			moveDirection = Vector3(1, 1.5, 0);
	 	 			moveDirection = transform.TransformDirection(moveDirection);
					moveDirection *= flightSpeed;
					curVelocity = moveDirection;
					if (touchingWall)
					{
						curVelocity = Vector3.Reflect (-curVelocity, Vector3.right);
					}
				}else if (isHolding==false)
				{
	 	 			moveDirection = Vector3(0, 0, 0);
	 	 			moveDirection = transform.TransformDirection(moveDirection);
	 	 		}	
			}
		}

Then ensure that when the touch is ended that the directional arrows are set back to un-rendered.

	 	if (touch.phase==TouchPhase.Ended)
	 	{
	 	 	ray = Camera.main.ScreenPointToRay (Vector3(touch.position.x,touch.position.y, 0));
	 	 	if (Physics.Raycast (ray,hit)&hit.collider.gameObject.tag=="Player")
	 		{
	 		     chargeTime=0;
	 		     isHolding=false;
	 		}
	}

set gravity flags

        moveDirection.y -= gravity * Time.deltaTime;
	controller.Move(moveDirection * Time.deltaTime);	
	
        var flags = controller.Move(moveDirection * Time.deltaTime);
	grounded = (flags  CollisionFlags.Below) !=0;
	touchingWall = (flags  CollisionFlags.Sides) !=0;
	touchingCeiling = (flags  CollisionFlags.Above) !=0;
				    
}

Essentially press and hold on the character brings up the arrows and starts the charge up that will rocket you further and faster the longer you hold. When you want slide your finger over the directional arrow you want and fly that way at that currently loaded flight speed.

Can you repost your code using ‘code’ tags?

Thanks for the tip, edited it in the first post.

I know it’s a bit of a long read but anyone have any thoughts?

Here’s a tip… if no one respond, try resume and simplify your question, making one at time. :wink:

Edited the first post, hopefully it breaks up the block of text a little bit and focuses the question. Thanks for the advice, been doing only the art side for so long still haven’t gotten the fine touches on communicating with this other side of the brain.

Okay, one more time I’m bumping this, if I don’t figure out how to convey it by now I’ll let it die. It’s only because I’ve hit such a roadblock I keep asking.

I have a character controller moving by…

//make the character move up and left
moveDirection = Vector3(1, 1.5, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= flightSpeed;	
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);

…and want him to ricochet off walls depending on what at angle he collides with it. I’m currently using collisionFlags but still not getting a change in direction.

Have you gotten this to work yet? I’m doing something similar and have it working. I’m using C#, but I can post some code if you still need it. I have an online demo you can check out here: http://quarksoda.com/amaz3d-live-demo.html

EDIT:
wow, just realized the timestamp says 2011, doh!