Welcome, Guest
Please Login or Register.    Lost Password?

Help with modifying script
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: Help with modifying script
#172
Help with modifying script 1 Year, 5 Months ago  
Hello XTUIO people, and thanks so much for UniTUIO!

I've had some troubles with a custom touchscreen sensor and finally found this, which will keep me from doing dirty tricks with mouse emulation to get things working. At least I hope so.

I'm more of a designer than a coder though, and have some problems modifying the BBBasicTouchManipulation.cs script. My setup is like this:

I have a CameraParent-object that has a camera as a child. Touching anywhere on the screen I want to be able to move this CameraParent around, rotate it, and with pinch-zoom change the distance from camera to cameraparent. This will be used to move a camera around above a city area.

In the attached script I have changed some things so that I can do this (except pinch-zoom). However, when I rotate and then try to move forward, the forward direction is not updated. I'm missing something here.

Code:


using UnityEngine;
using System.Collections;

// MANIPULATED BBBasicTouchManipulation.cs
// GOAL: single touch -> drag move along X- and Z-axis.
// GOAL: double touch pinch: Zoom (Move Camera closer to CameraParent)
// GOAL: double touch rotate: Rotate CameraParent around Y-axis
// GOAL: double touch move up/down: Tilt CameraParent along X-axis ()

// SUB-GOAL: If more than two points are detected  it will still rotate, zoom and so on. Its easy to accidentally touch the screen with other parts of your hand, especially if you use one hand with double touch gestures.

// rotate is in the plane of the camera

public class TUIOCameraController : BBSimpleTouchableObject {

public bool allowDrag = true;
public bool allowScale = true;
public bool allowRotate = true;

public float minimumScale = 1.0f;
public float maximumScale = 3.0f;

public GameObject CameraParent;

private Transform saveParent;
private Vector3 movement;

protected GameObject pivot;

public override void handleSingleTouch(iPhoneTouch touch) 
{
movement = touchMovementVector(touch);

movement.y = 0.0F; //LOCK MOVEMENT ALONG THE Y-AXIS

//if (movement.sqrMagnitude > 0.01) {    // USE THIS IF MOVEMENT IS JERKY. IT WILL FILTER OUT SMALL MOVEMENTS I GUESS.
    //this.startPivot(gameObject.transform.position); // MODIFY AND USE THIS IF PIVOT POINT NEED TO BE PLACED IN DIFFERENT PLACES DEPENDING ON TOUCH
CameraParent.transform.Translate(-movement,Space.World); // MAKE movement NEGATIVE TO REVERSE DIRECTION
//this.endPivot();
//}
}

//CODE CUT HERE --------------------------------------
// NEXT CHANGED PART IS THIS:

if (allowRotate) CameraParent.transform.RotateAround(CameraParent.transform.position,Vector3.up,angleDelta); //JUST ROTATE AROUND CameraParent CENTER

//CODE CUT HERE --------------------------------------------




So my questions:
1: How do I update the forwards direction? Or should I do this in another way?

2: This is attached to a invisible collider in front of the camera, but that will hijack all interactions with other objects right? How can I solve this?

3: Any advice on how to do the pinch-zoom to change distance between camera and cameraparent would be nice too.

4: Another problem: When using the unity editor everything works fine. When using TUIO SIMULATOR (by Martin Kaltenbrunner), motion will not stop until I stop holding mouse down. Is this normal?


Thanks in advance for any kind of help or advice on this!

/Gus
bode
Fresh Boarder
Posts: 5
User Offline Click here to see the profile of this user
Last Edit: 2010/09/03 21:11 By bode.
The administrator has disabled public write access.
 
#173
Re: Help with modifying script 1 Year, 5 Months ago  
Hey Gus,

Welcome! Unfortunately i am Away from the office, and i am only on iPad this Weekend. So i don't have Acres to my Codes... But far as i remember, there is a very nice Script on the unity Forums (iPhone Section) which is doing almost that what you want. Excepting the Camera Move Funktion. Please dig in there and if you don't find it, ask again - i can post something here on monday.

Cheers,

Sandor
sandor
Administrator
Posts: 115
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#175
Re: Help with modifying script 1 Year, 5 Months ago  
Thanks a lot for your quick reply Sandor!

I've been looking around in the iPhone section in the forums and have been able to hack something together that will rotate, pinch zoom the distance and move the camera parent around. It works almost as I want. I'll spend tomorrow on it aswell and hopefully get something working on monday.

Problem #4 from my previous post still remains though. In unity, touch works as expected, but with a Tuio Simulator, movement does not end until I release the mouse button. I dont have the opportunity to try on the real device until monday, so I dont know if its a problem or not.

Anyways, thanks for your help so far!

/Gus
bode
Fresh Boarder
Posts: 5
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#177
Re: Help with modifying script 1 Year, 4 Months ago  
Ok, things are moving along. I have one problem/question though. How does UniTUIO handle iPhoneTouchPhase.Ended? Im using a FingerManager from the forum. It responds well to Began and Moved, but not to Ended and Canceled.

Any thoughts on this? Any help would be really appreciated!

/Gus

Edit: This is the script I tried out: forum.unity3d.com/viewtopic.php?t=23835&...honetouchphase+ended

Couldnt get that particular script to work, but solved my problem by modifying some code that came with the UniTUIO download. (I needed to get touch position on phase.Ended)
bode
Fresh Boarder
Posts: 5
User Offline Click here to see the profile of this user
Last Edit: 2010/09/12 19:53 By bode.
The administrator has disabled public write access.
 
#179
Re: Help with modifying script 1 Year, 4 Months ago  
Hello.

I'm having the same problem, i can only detect the iPhoneTouchPhase.Began and iPhoneTouchPhase.Moved . Either the touch.phase == iPhoneTouchPhase.Ended or iPhoneTouchPhase.Canceled are not being detected.
Any ideas?
aslc
Fresh Boarder
Posts: 6
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#180
Re: Help with modifying script 1 Year, 4 Months ago  
I never got that to work, solved it with some not so beautiful code and moved on:) What are you trying to achieve? Maybe my approach can help you.
bode
Fresh Boarder
Posts: 5
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 12
Moderators: sloopidoopi