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 Babora · Dec 07, 2014 at 11:07 PM · quaternions

TransformDirection and Scale

I've made an empty game object that rotates with the keyboard input up to 80 and down to -80 eulers, and attached to it a gun item with a simple script.

 Rigidbody2D Bullet = Instantiate(bulletPrefab,transform.position,transform.rotation) as Rigidbody2D;
 Bullet.velocity = transform.TransformDirection(new Vector3(shootingSpeed,0,0));

**Since i'm just rescaling the whole character -1 when turning and TransformDirection doesn't get scaled, i get the effect in the picture: the velocity is set as if i didn't flip the object.*

I've tried by multiplying quaternions like this to no avail, most likely because i don't understand quaternions:

 Quaternion bonus = Quaternion.Euler (0,0,180);
 Quaternion newrotation = transform.rotation*bonus;
 Rigidbody2D Bullet  = Instantiate(bulletPrefab,transform.position,newrotation) as Rigidbody2D;

Any idea?

alt text

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 Baste · Dec 08, 2014 at 01:14 AM 1
Share

If you're trying to move the bullet forward with regards to the gun transform, just use transform.forward. See if this works:

 Bullet.velocity = transform.forward * shootingSpeed;
avatar image Babora · Dec 08, 2014 at 09:16 AM 0
Share

This is not applying any force and the bullet is just falling down due to gravity.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by static_cast · Dec 08, 2014 at 01:12 AM

Typically I would use Bullet.velocity = transform.rotation * shootingSpeed; to set the velocity.

Otherwise you would use TransformDirection like this:

Bullet.velocity = transform.TransformDirection(Vector3.forward) * shootingSpeed;

Comment
Add comment · Show 3 · 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 Babora · Dec 08, 2014 at 09:17 AM 0
Share

You can't multiply a quaternion (transform.rotation) for a float (shootingSpeed).

And this is not applying any force, even if i set shootingSpeed for an extremely high amount. Bullet.velocity = transform.TransformDirection(Vector3.forward) * shootingSpeed;

avatar image static_cast · Dec 08, 2014 at 04:14 PM 0
Share

Whoops sorry. This is what I meant to say:

Player.transform.forward * shootingSpeed;

I was referencing the wrong shooting script I had. ;)

$$anonymous$$ake sure Player is your, well... player. :)

avatar image Babora · Dec 08, 2014 at 09:01 PM 0
Share

Player's transform.forward can't help me. The player itself is not rotating. Using anything but TransformDirection(new Vector3(shootingSpeed,0,0)) is not setting any velocity. Isn't there a way to create a new quaternion that stores the modified rotation?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotate a Cube on swipe gesture iOS, for a specific time? 0 Answers

Rotating gears example 0 Answers

How to move relative to the orientation 1 Answer

How do i make my Mouselook behave when changing the z rotation? 0 Answers

Headlight rotation issue when moving the camera 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