Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 fadi · Mar 29, 2011 at 10:24 AM · collisionbulletshoot

shoot game - 2 problems

Hi there ... I'm trying to make a shooter game but I have 2 problems

1- I'm using this code for shooting :


var BulletPerfab : Rigidbody; var speed = 50; var FireSpeed : float = 0.2; private var NextFire : float = 0.0;

function Update () { if (Input.GetButton("Fire1") && Time.time > NextFire) { // create a new projectile, use the same position and rotation as the Launcher. var new_bullet : Rigidbody = Instantiate(BulletPerfab, transform.position, transform.rotation );

     // Vector3.X = speed , becuse the Global rotation of the player is (X = forward) , some time we put it Z that depeandes to the Global rotation
     new_bullet.velocity = transform.TransformDirection( Vector3( speed , 0 , 0 ) );

     // Ignore collisions between the missile and the character controller
     Physics.IgnoreCollision( new_bullet.collider, transform.root.collider );

     NextFire = Time.time + FireSpeed;   
 }

}


but the problem that the bullet need time to arrive to the wall , and if I increase the speed time of the bullet it's cross the wall with out make any collision, so is there a way to directly put the bullet on the wall, like OnMouseDown on the wall or Enemy the effect directly will show ?

2- how can I let the bullet when I shoot it ,go to the position(X,Y)/Direction of the shoot pointer(GUI). (The GUI it's not on the middle of the screen).

thanks....

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

1 Reply

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

Answer by Statement · Mar 29, 2011 at 02:21 PM

  1. Use Continous Physics or Raycast instead.
  2. Create a ray from the mouse position or another screen point and get the direction of the ray.

Something like this...

var prefab : Rigidbody;

function Update () { if (Input.GetButtonDown ("Fire1")) { var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var instance : Rigidbody = Instantiate (prefab, transform.position, transform.rotation); instance.AddForce (ray.direction * 100); } }

Comment
Add comment · Show 2 · 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 Bunny83 · Mar 29, 2011 at 02:28 PM 0
Share

I would also recommend to use a raycast. Direct hit weapons don't need bullets ;)

avatar image fadi · Mar 29, 2011 at 07:46 PM 0
Share

thank u .. but , I'm new in Unity so can u put a code about that

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

Bullet Effect 2 Answers

Destroy Projectile on collision 3 Answers

Why won't my bullets detect a collision and be destroyed?... 4 Answers

RayCast Problem : 2d 1 Answer

Bullet Shoot with RayCast don't destroy onCollisionEnter 1 Answer


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