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
5
Question by Milad · Apr 05, 2010 at 05:45 PM · simulation

Light gun simulation

Hi,

i want simulate light gun in my game.i have the light gun and is connected to pc and i can get the data(x,y).

now i want fire a projectile in x,y that i got from gun.i can do it but my projectile tent to center of screen beacause of perspective.i want it goes straight.

what must i do?

Comment
Add comment · Show 3
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 Milad · Apr 06, 2010 at 12:53 PM 0
Share

no answer? please help.

avatar image KHopcraft · Apr 08, 2010 at 06:20 PM 0
Share

Add some details please. If you give us something to work with, like script, we are able to answer your question better.

avatar image Milad · Apr 10, 2010 at 06:49 AM 0
Share

i want simulate light gun in unity3d.i can get my info(x,y coordinate in pixel) from external device(gun) and every thing is right until this point.

now when i get x,y i want instantiate a projectile in that coordinate and give a force or velocity that projectile goes straight.i did it but my projectile beacause of viewing system(camera) of unity and prespective when goes far it sounds that projectile goes to the center of screen.i do not know how can i add force to projectile that goese realy straight.

in fact i want simulate light gun like old 2d sega games.but my game is 3d.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by duck · Apr 14, 2010 at 02:16 PM

You need to use Camera.ScreenPointToRay. This gives you a ray whose direction runs from the camera's position in the direction of the screen point specified.

You would then use the ray.direction as your projectile's velocity. Eg - a script placed on the camera might include this function:

var bulletSpeed = 5;

function FireProjectile( screenX, screenY ) {

 var ray = camera.ScreenPointToRay (Vector3(screenX, screenY, 0));
 var bulletRotation = Quaternion.LookRotation(ray.direction);
 var bullet = Instantiate( bulletPrefab, transform.position, bulletRotation);
 bullet.rigidbody.velocity = ray.direction.normalized * bulletSpeed;

}

Comment
Add comment · Show 3 · 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 Milad · Apr 16, 2010 at 09:18 AM 0
Share

thanks for answer.i did it.but there is problem.when i fire in corners of screen the bullet have not a direct path and the bullet goes out of screen.furthermore when the bullet have gravity i have this problem.i got a video.please refer to video to get what i say. http://www.multiupload.com/LAZUICU9G2

so thanks for answer.

avatar image myunity · May 12, 2010 at 06:23 AM 0
Share

any other help please.

avatar image Milad · May 12, 2010 at 10:42 AM 0
Share

Please help more Duck.thanks.

avatar image
0

Answer by meunity1 · Apr 17, 2010 at 01:57 PM

i test that.i think this a bug!!!

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Fast way to find a specific myClass across many List? 1 Answer

Using cylinder colliders as wheels. 1 Answer

RigidBody Physics Flight Simulator Script Help 1 Answer

How to import the object from server to unity 2 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