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 FPS27 · Jul 15, 2011 at 05:12 PM · instantiatepositionfpsweapons

Projectile instantiation positioning is off.

I made some weapons for my FPS game. A Rocket Launcher and a Machine gun. When I fire them the Rocket/Bullet shoots forward but not out of the barrel of the weapons, it shoots out above. How can I fix this?

Screenshot:

alt text

JavaScript:

 var projectile : Rigidbody;
 var initialSpeed = 50.0;
 var reloadTime = 0.5;
 var ammoCount = 100.0;
 private var lastShot = -10.0;
 function Fire ()
 {
  // Did the time exceed the reload time?
  if (Time.time > reloadTime + lastShot && ammoCount > 0)
   {
   // create a new projectile, use the same position and rotation as the Launcher.
   var instantiatedProjectile : Rigidbody = Instantiate (projectile,
    transform.position, transform.rotation);
    
   // Give it an initial forward velocity. The direction is along the z-axis of 
   // the missile launcher's transform.
   instantiatedProjectile.velocity = transform.TransformDirection(
    Vector3 (0, 0, initialSpeed));
   // Ignore collisions between the missile and the character controller
   Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
    
   lastShot = Time.time;
   ammoCount--;
   }
 }
 

Projectile JavaScript:

 var explosion : GameObject;
 function OnCollisionEnter( collision : Collision )
 {
  var contact : ContactPoint = collision.contacts[0];
  var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal );
  var instantiatedExplosion : GameObject = Instantiate( 
                                    explosion, contact.point, rotation );
  Destroy( gameObject );
 }

Please can some one tell me if any of these scrips say where the 'Instantiate' position is, and how I can change that?

Thank you,

Comment
Add comment · Show 1
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 Chris D · Jul 18, 2011 at 10:18 PM 0
Share

Do not open duplicates of the same question. If you're not getting answers, it's likely because of how you've posed your question: format it and you won't make people's eyes bleed.

3 Replies

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

Answer by FPS27 · Jul 19, 2011 at 07:55 PM

I figured out the problem myself. I just needed to move the Launcher/MachineGun Game Object to the correct position.

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
1

Answer by Chris D · Jul 15, 2011 at 10:06 PM

Somehow you're instantiating from the wrong place. Check out where the instantiation is called from and see what it is using as a basis to tell your bullet to "spawn from this position".

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 S33HUNT · Jul 15, 2011 at 06:22 PM

... I think you need to divulge more info for a good answer. The script you're using would help. maybe a screenshot of the hierarchy to see how you're structuring your objects.

Is it an issue with local versus global positioning perhaps?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

FPS Instantiate position. Please help? 0 Answers

rigidbody bullets dont spawn where i want them too. 1 Answer

Select a child's variables from the parent. 1 Answer

Switching between gun positions 1 Answer

How to follow multiple clones positions of an instantiate prefab having a velocity ? 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