• 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 Jones_Soda · Apr 13, 2014 at 07:13 AM · collisionraycasttouchraycasthit

Touch collision detection with a sprite

Hello, I am making a 2D game on mobile devices with sprites as my "characters." In the game, you must be able to touch the screen on the sprite to make it bounce. I have tried using Physics.Raycast and RaycastHit, but they fail to work correctly. I believe it may be because the RaycastHit isn't working with my BoxCollider. Maybe and I should be using something else that the Raycast will be able to collide with. Here is the code for the collision:

var hit : RaycastHit; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, hit)) { gravity = 0; gravity += 0.35; randGravity = Random.Range(0.005, 0.015); text++; } I feel like this is a very basic issue and the answer is right in front of me, although I cannot find it. This is my first project working with Unity and I will greatly appreciate any help given to me. Thank you! :)

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

21 People are following this question.

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

Related Questions

How to check if a raycasthit detects an angle less than 45 degrees and touches the ground 2 Answers

raycast hit add force problem, help needed please 1 Answer

How can I change this script? 0 Answers

Multiple hit detection with Raycasting? 2 Answers

How can I make raycast touch responsive with 2d world objects? Raycast misses the collider when finger is moved at faster rate. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges