- Home /
iphone bullet through paper problem
I am using the iPhone and I have a problem tracking my finger movement. I have a sprite on screen and when I touch the sprite I want it to move where ever my finger moves. The problem is that I am moving my finger too fast and the script I wrote doesn't refresh enough to catch this case. Right now the script is FixedUpdate() function. Would the script update faster in the Update() function? Any help would be appreciated.
here is my code:
function Update() {
if(iPhoneInput.touchCount == 1 && iPhoneInput.GetTouch(0).phase == iPhoneTouchPhase.Moved) {
oneThrow.ray = Camera.main.ScreenPointToRay(iPhoneInput.GetTouch(0).position);
oneThrow.OldPosition = oneThrow.gameObjectGuy.rigidbody.position;
if(collider.Raycast(oneThrow.ray, oneThrow.mrHit, 1200)) {
//test code that occures when the ray has collided with //the booger
Debug.DrawLine(oneThrow.ray.origin, oneThrow.gameObjectGuy.transform.position , Color.red);
//end test code
//code oneThrow.StopChangeFromRandom = true; oneThrow.WalkLeft = false; oneThrow.WalkRight = false;
oneThrow.PackedSprite.defaultAnim = 2; oneThrow.PackedSprite.PlayAnim("Idle");
print("Ray Direction " +oneThrow.ray.direction+ "!!!");
oneThrow.gameObjectGuy.rigidbody.position = Vector3((oneThrow.mrHit.point.x), (oneThrow.mrHit.point.y), (oneThrow.mrHit.point.z));
}
oneThrow.rayValue = oneThrow.ray.direction.x; print("rayValue = " +oneThrowr.rayValue+ "!!!"); }
}
Answer by qJake · Mar 24, 2010 at 02:32 AM
Yes - your script will (most likely) update faster using just Update(). Why not just try it instead of posting here? It's not like your iPhone will explode if you substitute one for the other ;) Don't forget to use Time.deltaTime
for any movement calculations.
If your finger is still moving too fast, and you still need to detect collisions, I would suggest drawing a Linecast between the two positions of the object and checking collisions that way.
That fixed it up good. I forgot about the Time.deltaTime. Thanks man.
Your answer
Follow this Question
Related Questions
Block UnityGUI Hit 1 Answer
Add impulse force using input.touch 0 Answers
How do I enable iAds on my unity game for iPhone? 0 Answers
Unity iPhone scene transition on Tap of GUIText 1 Answer
Pokemon clone touch movement. 0 Answers