- Home /
Swipe Wind
Hi guys I have a question,
I want to make a script that lets me swipe my finger in a direction and the object ( the little orange ball) will get a force or velocity in the direction you swipe but also the strengt of the swipe. So if the swipe is short you will get a little bit force or the swipe is big your force will be greater.
I want to use this on the Iphone so a script with touch Is possible. Only curruntly I am not behind a mac computer so I cannot test it. So if the script can be test with the mouse input that would be great.
I use this script to calculate the swipe grapghic.
var targetPoint : Vector3;
function Update () {
if (Input.GetMouseButton(0)){
var playerPlane = new Plane(Vector3.forward, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
targetPoint = ray.GetPoint(hitdist);
transform.position = targetPoint;
}
}
}
I want to use physics so I can bounce of walls.
I have really no clue where to start. I searched the internet for soltions but there was no one post that could help me. Maybe I did mis some posts if is that the cause I hope you can redirect me to that post.
Thanks in advance.
Dennis Jongmans
Answer by wccrawford · Oct 13, 2011 at 03:11 PM
I don't do mobile development, but...
http://unity3d.com/support/documentation/ScriptReference/Input.GetTouch.html
It looks like you can use getTouch to determine when a touch begins:
if (Input.GetTouch(i).phase == TouchPhase.Began)
and ends (with TouchPhase.Ended) and use those to store the beginning and ending coordinates. Then just determine the distance from 1 to the other.
Alternatively, you could add up the delta distance for each touch and use that, applying it then the touch phase ends.
Answer by wccrawford · Oct 13, 2011 at 01:36 PM
You'll need store the initial point of the sweep. Then at the end of the sweep, calculate the distance and the direction and use that to apply force to the ball.
Yeah I was thinking the same thing, only I dont know where to start to calculate the direction and the force of the ball