• 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 sketch · Jul 01, 2010 at 04:31 PM · directionfirewronglauncherrocket

my rocket fires in the wrong direction

here's my rocket launcher code:

var projectile : Rigidbody; var initialSpeed = 20.0; var reloadTime = 0.5; var ammoCount = 20; 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--;
 }

}

and here's my rocket code:

// The reference to the explosion prefab var explosion : GameObject; var timeOut = 3.0;

// Kill the rocket after a while automatically function Start () { Invoke("Kill", timeOut); }

function OnCollisionEnter (collision : Collision) { // Instantiate explosion at the impact point and rotate the explosion // so that the y-axis faces along the surface normal var contact : ContactPoint = collision.contacts[0]; var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal); Instantiate (explosion, contact.point, rotation);

 // And kill our selves
 Kill ();    

}

function Kill () { // Stop emitting particles in any children var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter); if (emitter) emitter.emit = false;

 // Detach children - We do this to detach the trail rendererer which should be set up to auto destruct
 transform.DetachChildren();

 // Destroy the projectile
 Destroy(gameObject);

}

@script RequireComponent (Rigidbody)

so basically what happens is that the rocket fires in the wrong direction and more towards me

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 HolBol · Jul 01, 2010 at 05:04 PM 0
Share

can you please format ALL your code, it's very hard to read.

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Guru.du · Jul 01, 2010 at 06:15 PM

It appears that the orientation of whatever the script is attached to isn't right...for example, if u have a spawn point at the end of the rocket launcher it is probably rotated the wrong way. Instead of pointing away from you, it is pointing more toward you. Or a situation similar to that.

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 Mike 3 · Jul 01, 2010 at 05:51 PM

The code seems to be right (Though personally i'd use = transform.forward * initialSpeed; for the velocity just because it's a little easier to read - I aways get Transform Direction and InverseTransformDirection mixed up).

The only thing I can think of is that the forward vector of the missile launcher isn't pointing in the right direction

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 creative72 · Jul 01, 2010 at 05:56 PM

there are many things that may be creating this problem, the one that seems most likely is you may have your player backwards in local vs global space or something like that. making your initialSpeed var = -20 should do the trick.

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 creative72 · Jul 01, 2010 at 08:07 PM

there are many things that may be creating this problem, the one that seems most likely is you may have your player backwards in local vs global space or something like that. making your initialSpeed var = -20 should do the trick.

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 sketch · Jul 02, 2010 at 07:07 AM 0
Share

umm, I only started this project a couple of days ago - and im learning off tuts so could you please just show me where the speed is so i can change it - that'd be great thanks

avatar image sketch · Jul 02, 2010 at 07:16 AM 0
Share

i found the speed and set it to -20 but now my rocket fires in the right direction but flies backwards - ill keep notifying u but would simply rotating it do the trick?

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

No one has followed this question yet.

Related Questions

Asteroids moving in the wrong direction 2 Answers

Problems to project one vector over another 0 Answers

how to make rocket face right direction when lunched 1 Answer

Entity moving along the wrong axis 0 Answers

How to make RPG launcher shoot the rocket? 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