• 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 BuildIntoGames · Aug 21, 2013 at 08:30 PM · rotationinstantiatevelocitybulletprojectile

Gun Projectile Shooting In Wrong Direction (Javascript)

I created a gun script that will fire a projectile from a certain spawn point. The problem is, whenever it spawns, it instantiates going forward. If the spawn rotates (Lets say left) The bullet still shoots forward, not to the left. Help? Here's is the part of the code that instantiates a bullet prefab:

 var clone = Instantiate(projectile, spawn.transform.position, spawn.transform.rotation);
 clone.velocity = transform.TransformDirection(Vector3(0,0,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
2
Best Answer

Answer by Seizure · Aug 21, 2013 at 08:35 PM

It looks like you have it always going in the z direction maybe try:

rigidbody.velocity = transform.forward * 10;

Transform.forward

Or you could try

// Move the object forward along its z axis 1 unit/second. transform.Translate(Vector3.forward Time.deltaTime); // Move the object upward in world space 1 unit/second. transform.Translate(Vector3.up Time.deltaTime, Space.World);

(This is the one i use for bullets)

Transform.Translate

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 BuildIntoGames · Aug 21, 2013 at 08:43 PM 0
Share

Thanks bro! It worked! You just saved me hours of confusion, Thumbs up for you!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotation and Velocity of bullets. 1 Answer

instantiate finding upstream velocity 1 Answer

Projetil rotation in straight line trajectory 2 Answers

Fire Projectile based on Model rotation 1 Answer

Projectile over network problem 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges