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 $$anonymous$$ · Mar 13, 2013 at 11:35 PM · instantiateobjectvelocityspawn

Give object velocity based on spawn object rotation?

I have a spawn cube on the gun in my game. The Z axis of the cube is pointing forward away from the gun. I want to instantiate an object at that point with a random rotation (i have this working properly) but i cant figure out how to give the object forward(Z) velocity based on the spawn object and not based on the object spawned. How do i do this? an example script would be great, to help my understanding. Thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GADoyle · Mar 14, 2013 at 06:29 AM

instead of saying

 rigidbody.velocity = Vector3(0,0,20);

you should be able to say

 rigidbody.velocity = spawnObject.forward * speed;

the important part is the spawnObject.forward, that will return a normalized vector representing the direction that the spawnObject is facing.

though OperationDogBird is right, velocity is not usually set directly, it sounds like in the context you're using it, i should work.

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 OperationDogBird · Mar 13, 2013 at 11:51 PM

You should reference the spawn object when giving the initial velocity rather than using the newly spawned object. Something like

 var spawnObject:Transform;
 var projectile:Transform;

 function SpawnProjectile(){
     projectile = Instantiate(....
     projectile.rigidbody.AddForce(spawnObject.forward * 20,ForceMode.Force);
 }
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 $$anonymous$$ · Mar 14, 2013 at 12:10 AM 0
Share

that didnt work it just glitched up the gun and change the fire rate. and location of the spawn point. it didnt give the spawned object any velocity

avatar image $$anonymous$$ · Mar 14, 2013 at 01:23 AM 0
Share
 rigidbody.velocity = Vector3(0,0,20);

this is what i have now but this is based on the global rotation so no matter where i aim the object goes the same way. I want to change this so that it is based off of the rotation of a specified spawnObject.

avatar image OperationDogBird · Mar 14, 2013 at 06:18 AM 0
Share

I have never altered the velocity property directly as per Unity Docs "In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour." I always use the AddForce method, but i suppose you may have a reason for doing so.

As per my answer, reference whichever transform direction you need of the spawnPointObject. You will need a reference to the spawn point object, an example being: spawnPointObject.transform.forward.

If you are still having issues with this i suggest posting your code so (someone else) or i can write a more specifically accurate answer.

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

11 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

Related Questions

rate of spawn based on speed of object 1 Answer

Problem with Intantiate using uLink! 2 Answers

Self Clone 2 Answers

Spawning if there is space 1 Answer

how do I keep each cloned object at a certain point after trigger 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