Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jitthu · Jul 18, 2011 at 12:05 PM · raycastiphoneoptimizationdelaymouse input

Raycast Delay

Hi, I am trying to make a game which is similar to fruit ninja, in which u swipe to cut something. I am right now making it on the mac with the mouse(bcos i dont have iOS license). So what i do is i send a ray from the mouse position on screen whenever the user holds the mouse button and check with the 3dobjects(which are moving). So when i do a swipe with the mouse, sometimes it doesnt work. It only works when i move the mouse slowly. If i swipe very fast, most of the time the ray collides with nothing. I dont think it is because of the mac's performance because its an iMac. I have tried putting on FixedUpdate(), LateUpdate() nothing worked. I get an fps of 1500. I just want to know whether there is any other way i can check my collision or change my code in someway so the raycast is more faster. I also want to know whether this will become worse on the iPhone, because iphone is less powerful compare to iMac.


 ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     if(Input.GetKey(KeyCode.Mouse0))
     {
         trail.time = 0.2;
         if(Physics.Raycast(ray,hit,100)){
             
             if((Mathf.Abs(e.delta.x)+Mathf.Abs(e.delta.y))>0)//for checking drag
             {
                 hit2 = hit;
                 cubes = hit2.collider.gameObject;
                 cubes.SendMessage("Slashed");
             }
         }
     }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Fr0sZ · Jul 18, 2011 at 02:55 PM

Try checking if there is a object between the last 2 rays

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by drandx · Sep 16, 2011 at 10:12 PM

Hi I want to know if somebody has solved this, I'm having the same problem with the raycast delay, and i have spent a long time trying to get a solution.

Next, this is my script. This scripts Drag Objects, correctly, but when the movement is too fast, it seems like the raycast doesn't work.

private var targetItem : GameObject;

private var scrollDistanceX : float; private var scrollDistanceY : float;

var horizontalLimit : float = 2.9; var verticalLimit : float = 4.40;

function FixedUpdate() { if (Input.touchCount >0) {

     // finger data
     var f0 = Input.touches[0];
     
     // finger delta
     var f0Delta : Vector3 = new Vector3(f0.deltaPosition.x, -f0.deltaPosition.y, 0);
     
     
     //Ray Cast Info
     var hit: RaycastHit;
     var ray = Camera.main.ScreenPointToRay(f0.position);
     
     if(Physics.Raycast(ray,hit,100))
     {    
           targetItem = hit.transform.gameObject;
             
         
          if(f0.phase == TouchPhase.Moved)
          {
              

    
                  scrollDistanceX = targetItem.transform.position.x;
                 scrollDistanceY = targetItem.transform.position.y;
                 
                 var scrollDeltaX = f0.deltaPosition.x;
                 var scrollDeltaY = f0.deltaPosition.y;
                 
                 
                 scrollDistanceX = Mathf.Clamp(scrollDistanceX+scrollDeltaX*Time.smoothDeltaTime*0.5,-horizontalLimit,horizontalLimit);
                 scrollDistanceY = Mathf.Clamp(scrollDistanceY+scrollDeltaY*Time.smoothDeltaTime*0.5,-verticalLimit,verticalLimit);
                         
                         
                 targetItem.transform.position.x = scrollDistanceX;
                 targetItem.transform.position.y = scrollDistanceY;


                     
           }

     }
   }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by chirpytime · Dec 13, 2014 at 08:52 AM

A really old question; I'm curious if this can be solved by making the object's collider larger, or using a SphereCast instead of Raycast so it's less sensitive to mouse position changes?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a GetComponent array 1 Answer

help with iphone 3GS performance (polys and audio) 2 Answers

Large level loading best practices 1 Answer

Colliders vs RayCast (automatic crosshair aiming in an FPS game) 1 Answer

iOS. Jerks in first 15-20 seconds after starting scene 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges