going threw walls! 8(

hey, im using a script that is basically the standard to the input.gettouch sample to move my camera

var speed : float = 0.1;
function Update () {
if (Input.touchCount > 0 
Input.GetTouch(0).phase == TouchPhase.Moved) {

// Get movement of the finger since last frame
var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;

// Move object across XY plane
transform.Translate (-touchDeltaPosition.x * speed,
-touchDeltaPosition.y * speed, 0);
}
}

i have colliders set up around the scene to make boundaries. The problem is if i move my finger fast enough, the camera jumps right to the other side of the wall.

im believing that its because the position of my finger is on 1 side of the wall on frame 1, but then on frame 2 its on the other side, so it doesnt register the collider

anyone know how to stop this from happening?

The basic thing that I see is that you are using Translation with no boundary check. As far as I can see just in your script, even if you had a rigidbody and collider attached you would not get the correct results.

Consider either adding a boundary check, or rigid body and collider with collider boundaries. In the later you would not Translate, you would simply set the velocity of the rigidbody.

well i do have boundary checks also, your saying like

if ( transform.position.z > 3)
{
transform.position.z = 3;
}

correct? i have those and but some of the environments have a lot of cuts/edges to them so it would be a lot ezier of a solution to be able to use the colliders

i dont think velocity would really work with the method of moving i have going on right? how would i turn that into a velocity control?

just changed translate to

rigidbody.velocity = Vector3

it moves, but still can go right threw the wall

I assume: Input.GetTouch(0).deltaPosition; return the relative position of the object. So if you don’t move, the number is Vector2(0,0);?

Also, you are moving things around in X, Y. In game physics it would be best to move them X,Z, unless… you just turn gravity off.

var speed : float = 0.1;

function Update () {
	if (Input.touchCount > 0  Input.GetTouch(0).phase == TouchPhase.Moved) {

		// Get movement of the finger since last frame
		var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;

		// Move object across XY plane
		rigidbody.velocity(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
	}
}

function LateUpdate(){
	transform.position.z=0;
}

Make sure your walls and player have colliders. :wink:

sorry, the code i posted isnt directly from my script, im using a lot of variables to turn it on and off or use different parameters, so the one i posted is just the general idea,

im only moving it in x and z with this command, objects Y position is not effected by this, but like i said before changing it to a rigid body still lets me go right threw the collider 8(

duh! lol they both do, and it goes BING right threw lol

this has been an issue i found a long time ago when trying to use it to move a space ship around, and found i couldnt use it because the player would be able to go right threw buildings,

in other cases making the boundaries worked fine, and it looks like thats what im going to have to do, its just a lot more work 8( lol

but in any case for theoretical purposes id like to figure this out

i think its not picking up the collider because its not actually translating or moving the object directly, its acting more as a jump or telaport ,

its saying at frame 1 your finger is here, and at frame 2 your finger is here, and calculates the difference and moves the object in incriminates depending on the speed and the distance it needs to travel, so if the incriminates are to large it can skip right over the collider

close but still isnt quite working, i can still go right threw the wall if i try hard enuff until i lift my finger up, then it snaps the camera back behind the wall.

i tried the boundaries also and its still very glitchy, i cant go past the points i made but it tries to for 1 frame and goes back within the boundaries, almost causing a stuttering effect. this is also happening with the script posted by werewraith, regardless if its a rigidbody or not

So, your asking us to debug script that you are not using?

no not at all, its just a cleaner excerpt of the issue, so its ezier for you to see what im using

this is the exact full script

var target : Transform;
var distance = 0.0;

var xSpeed = 250.0;
var ySpeed = 120.0;

var yMinLimit = -20;
var yMaxLimit = 80;

private var x = 0.0;
private var y = 0.0;

@script AddComponentMenu("Camera-Control/Mouse Orbit")


var count = 0;
var speed = 0.01;

var guide : Transform;



function Start () {
	
	count = 0;
    var angles = transform.eulerAngles;
    x = angles.y;
    y = angles.x;

	// Make the rigid body not change rotation
   	if (rigidbody)
		rigidbody.freezeRotation = true;
}

	var rect = Rect (148,140,900,400);
var rect2 = Rect (148,0,550,800);




function FixedUpdate(){
	
		 if(Input.touchCount==1)
	 {
	 count = 0;	
	 }
	
	
		 if(Input.touchCount==2)
	 {
	 count = 1;	
	 }

		if(count == 0  Navi_GUI.S_on==1  screen_cast_top.scriptOn == 2)
	{
				
	if (rect.Contains(Input.mousePosition) || rect2.Contains(Input.mousePosition)  screen_cast_test_1.S_Enabled == 1  Input.GetTouch(0).phase == TouchPhase.Moved) 
	{

	// Get movement of the finger since last frame
	var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;

	// Move object across XY plane
	guide.Translate (touchDeltaPosition.x * speed,0,touchDeltaPosition.y * speed);


	}

		
		
		
	}

	
	if (count == 1  Navi_GUI.S_on==1  screen_cast_top.scriptOn == 2)
	{
	
		if (rect.Contains(Input.mousePosition) || rect2.Contains(Input.mousePosition)  screen_cast_test_1.S_Enabled == 1  Input.GetTouch(1).phase == TouchPhase.Moved) 
	{


			// Get movement of the finger since last frame
	var touchDeltaPosition1:Vector2 = Input.GetTouch(1).deltaPosition;


    if (target) {
        x += touchDeltaPosition1.x * xSpeed * 0.02;
        y -= touchDeltaPosition1.y * ySpeed * 0.02;
 		
 		y = ClampAngle(y, yMinLimit, yMaxLimit);
 		       
        var rotation = Quaternion.Euler(y, x, 0);
        var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
        
       guide.eulerAngles.y=rotation.eulerAngles.y;
        transform.rotation = rotation;
        transform.position = position;
        

    }
}
}
}





static function ClampAngle (angle : float, min : float, max : float) {
	if (angle < -360)
		angle += 360;
	if (angle > 360)
		angle -= 360;
	return Mathf.Clamp (angle, min, max);
}

if you really feel like reading threw it thats fine, but i just thought id make it ezier by taking out the only part that matters for this issue

That actually helps alot more than you can imagine.

First, lets change concept just slightly. Create a mesh which is your play area give it a mesh collider, make that collider a trigger.

Next, start this thing way out of the play area. Then in the first Update, move it to where it is supposed to be. (This is done because if an object exists inside of a trigger to start, it will not trigger the events that make it work.)

In your script, add LastPosition and LastRotation. These are holders for the last point where your player is while he was in bounds. (should be captured at the beginning of the update)

In your trigger, you want to maintain OnTriggerExit()… with that event, you will know what went out of your play area. If the object is your player, simply put him back to his last position and last rotation. :wink:

This method provides securely that he will NEVER leave his play pen. It will not, of course make him play nice with the other kids.

looks good so far, i understand the on trigger exit part, but how to i go about the last position?

thanks for all ur help by the way *D i really appreciate it!

As it sits, you are using everything in the FixedUpdate, This is not nessecary as you are using the delta to get the movement update as you go. I suggest using Update, and not FixedUpdate.

Create a couple of variables outside the Update and call it LastPosition and LastRotation. In the first part of the Update function simply make those equal to the position and rotation of your model.

If that model is the Target, then it would be:

LastPosition = Target.transform.position;
LastRotation = Target.transform.rotation;

Then in OnTriggerExit:

Target.transform.position = LastPosition;
Target.transform.rotation = LastRotation;

Before moving the character, couldn’t you do a raycast to see how close the wall is and use that to limit the motion?

I actually did this on an AI script, and found that I had to do 2 raycasts. O for the direction (a distance 5 times the movement value) and one for the normal based on the position of the unit of that hit to adjust for the size of my unit. It wasn’t as pretty as I had hoped.

it was a nice idea… but still isnt working properly 8( it still glitches along the boarders, it goes slightly outside the room, shows outside for a frame or so, then goes back to the last position

also it still glitches out and allows me to go completely outside the space,

the boundaries seem to be the closest thing to work right, but obviously not other games arnt having an issue where you can see through the walls for a frame before going back into the room, i may have to rethink how the camera is being moved 8(

i think thats what the link to the script above is doing, the problem is that i can sometimes force my way through the wall still, and if i keep my finger down i can move on the other side. i dont snap back to the proper side of the wall until i lift my finger up