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 N00basaurusRex · Aug 31, 2017 at 06:24 AM · c#animationmovementrigidbodyprefabs

Instantiated Bullet Lags Behind Animated Timeline Object

Bullets are created on fire input with a rigidbody and an "AddForce". The ship is animated along a course via the new Timeline editor. But when the player shoots, the bullets aren't moving "with" the ship. I can speed them up to sort of "catch up" and take the ship over but It looks wrong and the bullets end up moving crazy fast.

Standing still the bullets work great, shooting out and away from the front of the ship. But moving, the animation is just too fast for the instantiated bullets and they don't count for how fast the ship is currently moving.

I also have other ship weapons that have fun stuff like shell casings that just vanish out of view because they can't keep up and I don't want them to shoot away like bullets by adding force to them. They need to be more lazy and slowly arc towards and away from the camera attached to the player.

In the image, the bullets are behind the ship when they should be coming out of the front and moving away from the ship, even while the ship moves along it's animated rail via the Timeline.

From what I understand, rigid bodies on the ship/children have a velocity of zero because the animation overwrites physics. so isntant.rigidbody.vellocity = ship.rigidbody.velocity has no effect...

Is there a way to child the bullets through the hierarchy so that they move normally (in front of the ship) instead of lag behind? So, as an example, the ship would have a child empty object where the bullets would nestle under as soon as they come into existence. That way the parent's motion would count towards the force and power of the prefab child bullet/shell casing/whatever I want to throw under it...

anyone have any suggestions on how to get this to work?

my bullet scripts are in two places.

First is the player input controller for instantiation:

  Instantiate(bulletPrefab, bulletSpawner.transform.position, Quaternion.identity);

and bullet prefab itself:

 public float shootPower = 5000f;
     public Rigidbody rb;
     public Rigidbody spawnerRb;
     
     public GameObject bulletSpawnPoint;
     public GameObject particlePretty;
 
     
     void Start () {
         bulletSpawnPoint = GameObject.Find("Bullet Spawn 1");
         spawnerRb = bulletSpawnPoint.GetComponent<Rigidbody>();
         rb = this.GetComponent<Rigidbody>();
         rb.velocity = spawnerRb.velocity;
         rb.AddRelativeForce(bulletSpawnPoint.transform.forward * shootPower);

... //and then the rest is die after x seconds function as well as a particle spawn on colliison

ship-but-small.gif (486.4 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Aug 31, 2017 at 09:36 PM

The first thing that comes to mind is that you're calling "AddRelativeForce" with a non-relative vector. You should use AddForce or simply Vector3.forward. Depending on how your scene is set up, that may actually be slowing them down.

Comment
Add comment · Show 4 · 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 N00basaurusRex · Sep 01, 2017 at 05:29 PM 0
Share

I tried animating an empty game object then setting another object's transform to that. velocity of the non-animated object was zero as well.

What I'm asking is "how do I negate the speed and direction of an object on a pre-dertimed path/rail so that objects aren't spawned too slow to start and the force won't change depending on object's direction." For example, an object moving backwards with a forward firing bullet will perceive the bullet to fire faster than an object moving forward with the forward firing bullet.

The gif above shows a forward moving object shooting forward bullets.

avatar image FortisVenaliter N00basaurusRex · Sep 01, 2017 at 08:10 PM 0
Share

Right, and it looks like you are doing that. I would set the initial velocity to the source velocity before adding force, and that's exactly what you're already doing.

avatar image N00basaurusRex FortisVenaliter · Sep 03, 2017 at 05:19 PM 0
Share

Watching the values in the debug, velocity is zero if you aren't using forces on a rigid body. I tried calculating velocity via transform ( [old-new].magnitude / time.deltatime) but because it's based on the coordinate plane, that calculation isn't normalized and increases/decreases based on how far away you get from (0,0,0).

I thought about animating the bullets, but it would have the same effect unless if I wanted the bullets to move with the character/object ins$$anonymous$$d of the nice fire and forget that I have with the physics sim.

I'm thinking the only way to get the desired effect is to just slow the ship down. If it has a slower speed it will be easier to match the bullet's forward movement with the ship and not lag behind so much. Only issue is trying to figure out how to explain why the high-tech space ship is moving so slowly to the player...

Show more comments

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

436 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Animate Character movement? 1 Answer

isKinematic object doesnt collide with wall 3 Answers

Why does my character keep sliding around? Help! (Rigid Body) 1 Answer

Move left etc. according to where player faces 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