Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Kyle 10 · Apr 22, 2011 at 07:26 PM · rotationrigidbodyinstantiateaddforce

Rotation problem with spawning bullet

I have had this problem a couple of times and i always forget how i fix it.What i am trying to do is make a bullet spawn in front of the barrel and add a force to move it forward and no matter what i do the bullet just moves to the left of the gun... Can someone please explain to me(EXPLAIN TO ME) how to fix this so i will always have a reference to solve this problem.

oh yea the code...

var bullettype : Transform;

var spawnspot : Transform;

var bulletspeed : float = 500.0;

function Update () {

if(Input.GetButtonUp("Fire1")){

var shot = Instantiate(bullettype,spawnspot.transform.position,spawnspot.transform.rotation);

shot.rigidbody.AddForce(transform.forward * bulletspeed);

Debug.Log("Fired");

}

Comment
Add comment · Show 2
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 · Apr 22, 2011 at 07:30 PM 2
Share

Please format your code appropriately when posting it (the 101010 button in the formatting box) as it makes it easier for people to read.

avatar image Kyle 10 · Apr 23, 2011 at 01:47 AM 0
Share

ok thanks i didnt really realize that so sorry ill get it next time :D

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Chris D · Apr 22, 2011 at 07:39 PM

What it sounds like is that, while you're spawning the bullet in at the spawnspot's position and rotation, spawnspot's transform might not be pointing in the correct direction in the first place; I'd check that first.

If that's not the case, try pausing the game directly after the bullet is spawned and seeing how it's axes differ from the spawnspot's transform - that should give you a better indication of what's off, relation-wise.

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 loopyllama · Apr 22, 2011 at 08:33 PM

your bullet rotation is set to the rotation of spawnspot but you are adding force in the direction of the object this script is attached to. try spawnspot.transform.forward instead of transform.forward

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 loopyllama · Apr 22, 2011 at 08:36 PM 0
Share

and I don't want to say you don't need a rigidbody with physics for your bullets...but you probably don't need a rigidbody with physics for your bullets. just update the bullet transform each frame rather than using the physics to drive the bullet.

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

Airplane goes weird on collision (Rigidbody) 1 Answer

Rotating Camera, and Movement help. 1 Answer

Instantiating bullet and moving forward with rigidbody 0 Answers

Prevent Rigidbody From Rotating 3 Answers

I need help with rotation 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