- Home /
Box Drag and throw away script for mobile?
Hi i everyone i was working on my game in which in one part the player has to Drag the boxes outta his/her way so i tried unity3d's default rigidbody dragger(Scripts Package)but it's spring like working is both good and bad but i guess it's about the best result i've got so far.The problem with this one is that once i release it goes flying up high ! Then i tried another code found here(http://answers.unity3d.com/questions/498396/how-to-click-and-drag-an-object-at-full-speed.html)but this one's too dependent to the player once i release the mouse it'll be freezed in it's place and wont keep on going which is bad for gameplay cos like this player wont be able to move lots of boxes one after another!I also tried http://youtu.be/QjUhQ4z6pF0 but it aint moving at all i did some minor changes in code but then it started moving like what was shown in the video and we were told that it was unity remote's problem(or sth like that :D)!Here's my edited version of that code:
public var Target:GameObject;
public var XLimit:float = 2.5;
public var YLimit:float = 2.5;
public var ScrollDistanceX:float;
public var ScrollDistanceY:float;
public var Hit:RaycastHit;
public var layermask = (1 << 8) |(1 << 2);
function Start () {
ScrollDistanceX = transform.position.x;
ScrollDistanceY = transform.position.y;
}
function Update () {
if(Input.touchCount > 0 )
{
var TheTouch :Touch = Input.GetTouch(0);
var MyRay = camera.main.ScreenPointToRay(TheTouch.position);
if(Physics.Raycast(MyRay,Hit,layermask))
{
if(Input.touchCount == 1)
{
// Destroy(Target);
var ScrollDeltaX = TheTouch.deltaPosition.x;
var ScrollDeltaY = TheTouch.deltaPosition.y;
//ScrollDistanceX = Mathf.Clamp(ScrollDistanceX + ScrollDistanceX*Time.deltaTime*0.5,-XLimit,XLimit);
//ScrollDistanceY = Mathf.Clamp(ScrollDistanceY + ScrollDistanceY*Time.deltaTime*0.5,-YLimit,YLimit);
/*Target.transform.position.x = ScrollDistanceX;
Target.transform.position.y = ScrollDistanceY;
Target.transform.position.x=ScrollDeltaX*0.05;
Target.transform.position.y=ScrollDeltaY*0.05;
}
}
}
}
Anyone know how to fix this problem ?I mean u dragg a box in a path of ur own once u release it it'll keep on going a bit too!I'm looking for sth close to Corona SDK's Drag object example(Anyone who has worked with that program will probably know what i mean)or sth which is at least as smooth as bad piggies system but with the keep moving part ofcourse :(
Your answer
Follow this Question
Related Questions
Dragging Camera based on Touch 0 Answers
Dragging UI Image by touch 3 Answers
Do UI Buttons work the same for Touch for an Android Game? 1 Answer
Why this simple code doesnt work? 0 Answers