Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 overunity3d · Aug 05, 2011 at 02:29 AM · addforcedirectiontravel

The direction of travel is not rotating with the projectile in the spinning GameObject.

I fire a projectile into a rotatable GameObject. The projectile is traveling from the top of the screen to the bottom of the screen. In looking down on it I spin the GameObject, lets say in a clockwise direction. The projectile's position follows the spin of the GameObject. If I stop the GameObject at 180 degrees rotation the projectile continues to travel to the bottom of the screen where it should have had its position rotated and the force(?) too. The Force is always going in the direction of firing or the rebounding. It must get this from the GameObject. So do I need to continuously update some physics parameter to change the direction of force or travel of the projectile from some rotation parameter of the spinning GameObject? Note: I do not use gravity.

 var Opponentshoot = Instantiate(Opponentshoot,  GameObject.Find("SpawnPoint").transform.position, Quaternion.identity);
 //var Opponentshoot = Instantiate(Opponentshoot,  GameObject.Find("SpawnPoint").transform.position,transform.rotation);
 Opponentshoot.transform.parent = GameObject.Find("Phyzx").transform; //This causes curved trajectory!!!
 Opponentshoot.rigidbody.AddRelativeForce(Vector3.forward * 50000);
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

5 Replies

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

Answer by overunity3d · Nov 20, 2011 at 04:56 AM

http://answers.unity3d.com/questions/187426/weird-rotation-with-camera-no-code-issue.html @overunity3d: well, that's what i said. Rigidbodies are ALWAYS simulated in world-space even when they are childs of other objects. The documentation mentioned that, not very clearly but it is there: Rigidbody component.

In general you should avoid parenting a rigidbody to another moving / changing object. The position will be translated (so it will move along with the parent) but all physics properties (esp. velocity) will stay in world space.

The problem in the video is that a physics system tries to simulate the real world. Due to momentum an object will always try to keep moving at it's current velocity and direction. In space you can orbit around large object because of gravity (not the simplified earth-gravity). If there's no gravity between the orbitting object and the object in the center it can't orbit, why should it? (1 hour ago) Bunny83

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 overunity3d · Nov 20, 2011 at 03:16 PM 0
Share

http://www.youtube.com/watch?v=Vi4XTYREXv0

http://www.youtube.com/watch?v=9yi5knkcTnc

I realized I need to rotate the camera around a point and not spin the world. The Physx engine has inertia in it and I cannot alter or force the parameters that feed this process. $$anonymous$$y bonehead mistake. The player turns in space and yes the world does not revolve around the player. I finally see the error of my logic.

avatar image
4

Answer by aldonaletto · Aug 05, 2011 at 03:47 AM

It's somewhat confusing, but I assume at first your projectile trajectory is being altered by the rotation of some object, and that you don't want this. Am I right? If so, you must not make this object parent to the projectile, because any parent rotation will affect its children. If you need to child the projectile to something for any reason, create an empty object and child the projectile to it (and, of course, don't move or rotate this object).

On the other hand, if you want the trajectory to be somewhat affected by rotation of other object, after the initial AddForce you can apply to the projectile at FixedUpdate a force based on some object's vector - something like this:

function FixedUpdate(){
  Opponentshoot.rigidbody.AddForce(object.forward * 1000);
}
This is just pseudo-code, of course - Opponentshoot, for instance, is a local variable of your other function, and would not be known in FixedUpdate - but I suppose it can give you the basic idea.

EDITED: To make the projectile rotate with the parent object, you can't use AddForce or set rigidbody.velocity - you must translate the projectile in its forward direction.
You will need two scripts: one similar to yours, but that just create the projectile, and the projectile script, which will move itself and check collisions. The shooting script is like yours:

var Opponentshoot: GameObject;

function Shoot(){ var daddy = GameObject.Find("Phyzx").transform; var spawnPt = GameObject.Find("SpawnPoint").transform; var opponentshoot = Instantiate(Opponentshoot, spawnPt.position, daddy.rotation); opponentshoot.transform.parent = daddy; // the projectile is still childed to Phyzx } The projectile script must be added to the projectile prefab, and is very simple:

var speed: float = 50; // projectile speed

function Start(){ // projectile live 10s at most Destroy(gameObject, 10); }

function Update(){ // move the projectile to local forward direction transform.Translate(Vector3.forward speed Time.deltaTime); }

function OnCollisionEnter(col: Collision){ Destroy(gameObject); // destroy the projectile if something hit // you can do other things here, like add points, // instantiate an explosion, or play a sound etc. }

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 aldonaletto · Aug 06, 2011 at 01:09 AM 0
Share

This answer was edited to show how to rotate the projectile trajectory. This time a routine similar to yours just create the projectile, while the projectile script will translate it. Take a look to the edited answer and, please, reply using add new comment. The Answer box must be used only to answer the question, not for replies, comments, etc, because this mess things up a lot (even I am getting confused with so many answers and comments).

avatar image
0

Answer by overunity3d · Aug 05, 2011 at 04:06 AM

As the GameObject rotates the projectile also loops around because it is Off center. But the projectile's trajectory does not change with respectu To its new position. The trajectory always maintains it initial direction. I will try your fixedupdate() placement. So the trajectory needs to be dynamically Updated as its parent changes?

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 aldonaletto · Aug 05, 2011 at 12:15 PM 0
Share

$$anonymous$$an, I sware I didn't get exactly what you want to do. Do you want to:
1- $$anonymous$$ake the projectile trajectory follow any parent object rotation - kinda running on a straight rail which is part of the parent;
2- Control the direction of the projectile with the parent object: if the parent rotates to the left, the projectile turns to that direction;
3- None of above;

avatar image overunity3d · Nov 20, 2011 at 04:56 AM 0
Share

choice number 2

avatar image
0

Answer by overunity3d · Aug 05, 2011 at 03:55 PM

Option 1.

If the projectile is on the left side and I fire it without the Parent rotation the projectile will go to the right side. Simple. If the parent is rotated the child projectile position rotates with the parent. The projectile does not rotate on its own axis. It is in space so it's local rotation could be anything. Back to referring to the projectile trajectory: If I rotate the parent the projectile trajectory still goes from left to right even though the world position of the projectile child moves. If I fire the projectile child to a target in the parent GameObject the projectile child should travel towards the target regardless of the rotation of the Parent GameObject.

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 aldonaletto · Aug 06, 2011 at 01:01 AM 0
Share

I edited my answer to make what I think you're trying to do. This time a routine similar to yours just create the projectile, while the projectile script will translate it.
Take a look to the edited answer and, please, reply using add new comment. The Answer box must be used only to answer the question, not for replies, comments, etc, because this mess things up a lot (even I am getting confused with so many answers and comments).

avatar image
0

Answer by overunity3d · Nov 20, 2011 at 03:05 PM

How do we create things moving in a gameobject but spin that gameobject with the objects in that gameobjects moving correctly, like fire and forget? we fire a missile then turn away but the missile stays on track? As you can see in my video the objects just swish around instead of staying on track. But let me specify that the objects don't have a target just a straight forward destination in the spinning game object. (10 hours ago) overunity3d

Thanks guys. I realized I need to rotate the camera around a point and not spin the world. The Physx engine has inertia in it and I cannot alter or force the parameters that feed this process. My bonehead mistake. The player turns in space and yes the world does not revolve around the player. I finally see the error of my logic.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

For some akward reason bullet is moving in the wrong direction 1 Answer

Local Direction of Vector3 1 Answer

Physics2D AddForce Direction Vector Issue 1 Answer

addForce (IMPRECISION?) object changing direction after a few frames of launch... 6 Answers

how can i rotate the ball in left direction deirection if it was in forward direction and vice versa , like a real ball? 2 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