Hi,
i am trying to move a character in a specified path , path is nothing but in which i moved my finger .
but character should start after my touch end and it should turn in the required directions
Any suggestions??
any help ??
Thanks
Hi,
i am trying to move a character in a specified path , path is nothing but in which i moved my finger .
but character should start after my touch end and it should turn in the required directions
Any suggestions??
any help ??
Thanks
As you’re dragging, create a Transform object (waypoint) every so many frames/seconds/pixels/units that has the same position as the touch, if it were cast into the game world through Camera.ScreenPointToRay();
You could potentially figure out the rotation from the positionDelta’s of the touches, or just by having the character turn to face the next waypoint…
When the touch is finished, start moving the character along the path that was recorded, deleting it as you go.
Hi
I am trying to do something similar: I have a pre-defined path (as a line drawn in the scene) that I want a character to move along. Whats the most efficient way to do this? By waypoints do you just mean
an array of transform positions and rotations?
Thanks.
That’s exactly what I mean - yes.
How is this line created? If it’s made from a bunch of bezier nodes then you could probably use the nodes themselves as waypoints, althrough rotation would matter.
Hi,
here i created a .js script , in which i am collecting all my finger touch points and storing in a array. and on end of my touch i am applying that position array to the character. but no use . it is not translation also suddenly on my touch end it is shifting to the last position.
here i am pasting my code , please correct if any mistakes and plz modify this
var positonArrey : Array = new Array();
var _hit: boolean = false;
function Start()
{
}
function Update ()
{
for(touch in iPhoneInput.touches)
{
if( touch.phase == iPhoneTouchPhase.Began || touch.phase == iPhoneTouchPhase.Moved)
{
var objScreenPos = Camera.main.WorldToScreenPoint( transform.position );
if( Hit(touch.position, objScreenPos) )
{
_hit = true;
//var touchWorldPos : Vector3 = GetPerspectiveWorldPos(touch.position);
}
if (_hit)
{
positonArrey.Push (touch.position);
for (var i in positonArrey )
{
print (“iiiiiiiiiiiiiiiiiii”+i+“---------”);
}
}
}
if( touch.phase == iPhoneTouchPhase.Ended )
{
_hit = false;
for (var i : int = 1; i< positonArrey.length; i++ )
{
var pos: Vector2 = positonArrey*;*
Hi Vidya,
did u get any solution for this ??
if u got it can you please share it once
Thanks
The problem with your script is that it is setting the object’s position repeatedly within the same frame. If you do this, only the last position will have any effect, which is why your object jumps directly to the last touch position. I’ve attached a script that should help you see what you need to do here. It takes an array of Vector3 points as a path - when you set the “moving” variable to true, it will start moving the object along the path defined by the points at a steady speed (make sure you set the speed variable too, or nothing will happen). Essentially, your script should have two phases - one where it records the path and another where it “plays back” the recorded movement using something like the PathFollow script.
194841–6947–$pathfollow_195.js (1.01 KB)
Hi andeeee,
Thanks for your rply , but no where you discussed about
touch detection.
can you give me a script with touch phases also
Thanks in Advance
I am modifying your script to give touch events .
like this , i written very big comments in side please go through it once and tell me where i am doing wrong
var points: Vector3[ ];
var moving: boolean;
var speed: float;
var currentPt: int;
var startPos: Vector3;
var endPos: Vector3;
var stepStartTime: float;
var stepDuration: float;
var finishedStep: boolean;
////////
var _hit: boolean = false;
function Start() {
finishedStep = true;
}
function Update ()
{
for (var touch in iPhoneInput.touches )
{
if (touch.phase == iPhoneTouchPhase.Began || touch.phase == iPhoneTouchPhase.Moved )
{
var objScreenPos = Camera.main.WorldToScreenPoint( transform.position );
if( Hit(touch.position, objScreenPos) )
{
_hit = true;
}
if (_hit)
{
points.Push(touch.position);
** //Here iam getting the error in the script like PUSH is not a member in UnityEngine.Vector3 but we took Vector3 areey then why it is giving the error**
for (var i in points )
{
print (“iiiiiiiiiiiiiiiiiii”+i+“---------”);
}
}
}
}
if (moving)
{
if (finishedStep)
{
if (currentPt == (points.Length - 1))
{
moving = false;
currentPt = 0;
return;
}
startPos = points[currentPt];
endPos = points[currentPt + 1];
currentPt++;
var dist = Vector3.Distance(startPos, endPos);
stepDuration = dist / speed;
stepStartTime = Time.time;
finishedStep = false;
}
var progress = (Time.time - stepStartTime) / stepDuration;
if (progress >= 1.0)
{
transform.position = endPos;
finishedStep = true;
}
else
{
transform.position = Vector3.Lerp(startPos, endPos, progress);
}
}
}
function OnDrawGizmos() {
if (points.Length == 0) {
return;
}
for (i = 1; i < points.Length; i++) {
Gizmos.DrawLine(points[i - 1], points*);*
Your points var is a builtin array, not an Array(). Builtin arrays don’t have a Push() method because they’re not mutable (as in, if you want to increase the size to add a new value you have to create a new array).
For what you’re doing, using a javascript Array() makes more sense. Try changing your var declaration from Vector3[ ] to Array.
i got the solution , but it is working fine if camera angle is zero , if i rotate camera by 65digrees in X-axis it is not working fine , it is taking some more offset in positions
if anybody have solution please tell me , iam attaching the script here
195223–6956–$doll_282.js (2.1 KB)
Hi ,
This script is attached to camera or 3d object??? It is not working???
I need a script, to draw a line path over the Iphone screen with the finger, any help?