Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
1
Question by BrinkHouseGames · Aug 06, 2013 at 01:56 AM · javascriptrotate objectoffsettransform.rotation

Adding an offset to an instantiated objects rotation

I'm instantiating an object at another objects transform.position and transform.rotation and shooting it forward (it's a bullet) however I want to add an offset so that I can have the trajectory be offset +/- from the transform.rotation direction. Using Javascript in the previously written code. Please let me know if I can be more clear.

Here are the pertinent lines:

 var roundClone : Rigidbody = Instantiate(round, transform.position, transform.rotation);
 
 roundClone.velocity = transform.TransformDirection(Vector3.up * roundSpeed);

Thank you!

Comment
Add comment · Show 6
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 robertbu · Aug 06, 2013 at 02:00 AM 0
Share

Depending on your goal, there are a number of ways. A simple way which may or may not be what you are looking for is to:

 roundClone.transform.Rotate(offsetX, 0.0, offsetZ);

I used x, and z here since you are adding velocity in the up direction.

avatar image BrinkHouseGames · Aug 06, 2013 at 02:18 AM 0
Share

'roundClone' is a Rigidbody, so roundClone.Rotate isn't being recognized as a member.

avatar image robertbu · Aug 06, 2013 at 02:20 AM 0
Share

I should have caught that. I edited the comment. So is this what you are looking for, or do you need something else to solve your problem?

avatar image BrinkHouseGames · Aug 06, 2013 at 02:37 AM 0
Share

That doesn't seem to change anything. I was able to get the effect by rotating the object the transforms are pulled from so that the axis was ai$$anonymous$$g 45 degrees from center but I need to do it in code as I'll have a round shooting straight, and then one on either side at a 30-45 degree angle from it, basically a tri-shot effect as illustrated below. Let me know if that makes no sense. :)

alt text

screen shot 2013-08-05 at 7.36.17 pm.png (16.8 kB)
avatar image robertbu · Aug 06, 2013 at 03:17 AM 0
Share

The line of code I handed needs to be called before you assign the velocity. Your problem is made more difficult because it appears from your code that you are firing it in the object Transform.up direction. There is a lot of code samples that assume that you fire/move objects in the forward direction.

$$anonymous$$aybe I'm mistaken about what you want to rotate. You can use transform.Rotate() to rotate whatever object is spawning the 'round'. Since the instantiated round, get the transform rotation of the object spawning (because you are passing it as a parameter), then rotation the spawn object will rotate the 'round'

Here is an alternate way to delta rotate:

 transform.rotation = Quaternion.Euler(rotx, roty, rotz) * transform.rotation;

But if the earlier code did not work, this is likely to have the same issues whatever it is.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

14 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

Related Questions

How to pass function as parameter to function? 1 Answer

How to delete new'd arrays? 2 Answers

UnityEngine.Rect' does not have a visible constructor that matches the.... 1 Answer

How to create random movement in 2D 2 Answers

Coroutine gets skipped in javascript/unityscript 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