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 Om3n · Mar 14, 2012 at 12:16 AM · rotationrigidbodyinstantiationprimitivesvector3.up

Instantiation causing issues x,y

I've been fighting this a few days now. I've been playing with a few basic primitives to get a top down view working, as well some some basic form of shooting. However when I rotate the object the instantiated bullets fires off in two directions seemingly on the opposite axis from what that character primitive is facing. Here's what I have atm in the script which isn't much. I'm using the x,y axis and have the Z poking me in the face. The instantiation also seems to stay in the middle of the camera view instead of spawning where the primitive has been moved to. Any thoughts or at least what I'm doing wrong would be appreciated.

 function Update () {

 if(Input.GetKey(KeyCode.Space))
 fire();

 if (Input.GetKey(KeyCode.RightArrow))
 //turret.transform.rotation.z += 0.01 * moveSpeed * 100;
 turret.Rotate(Vector3(turret.position.x,turret.position.y,100) * Time.deltaTime);
     print(turret.rotation);
 
 if (Input.GetKey(KeyCode.LeftArrow))
 //turret.transform.rotation.z -= 0.01 * moveSpeed * 100;
 turret.Rotate(Vector3(0,0,-100) * Time.deltaTime);    
     print(turret.rotation);
 


}

function fire() {

 var clone = Instantiate(bullet, turret.transform.right , turret.transform.rotation);
 bullet.rigidbody.AddForce(transform.forward * speed);
 

}

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

Answer by DaveA · Mar 14, 2012 at 12:23 AM

Instantiate(bullet, turret.transform.right

turret.transform.right is a direction, defaulting to 1,0,0, so to use it as a position, not too good.

If you want the bullet to spawn at the end of the muzzle, you can put a dummy (empty) object (transform) at the end of the muzzle (parented to the muzzle), and get its world position at the time of firing.

Then add force in the direction the turret is facing, namely, turret.transform.forward (probably)

Comment
Add comment · Show 1 · 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 Om3n · Mar 14, 2012 at 12:45 AM 0
Share

Thanks for the answer. I fixed half the issues thanks to your input, but I'm still finding the turret end is firing from 2 ends of the primitive. It doesn't seem to matter if the addforce is in there or not. http://s16.postimage.org/3ke6tsvjp/Untitled.png is a screen of what's going on.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can i Move/Rotate triggers without Rigidbodies? And other collider questions. 3 Answers

Pysics not working as expected 1 Answer

Oculus VR Wrist Rotation Relative to Arm 0 Answers

Child affecting parent rigidbody? 1 Answer

Add relative force to other object 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