Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
0
Question by DevMerlin · Oct 31, 2012 at 12:55 AM · cameraphysicsvector3launchthrow

How do you aim towards mouse when two objects are moving?

I'm trying to build a fairly simple 2D sidescroller, where the player does not control the actual character but helps them along by tossing objects at them. However, I've hit a problem - when using the mouse to target a section of screen and two objects are moving, there is a lag time where the object will fall behind the player and character and not to the relative position.

alt text

I've gotten this far:

         // Launch Position
         Vector3 cameraPosition = Camera.main.transform.position;
         
         // Mouse Position
         Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 12f));
     
         GameObject _object = items[i];
         
         // Create Item //
         GameObject _item = Instantiate(_object, cameraPosistion, Quaternion.identity) as GameObject;


But I'm utterly stumped on what to do next. The items have rigidbodies attached and use physics.

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 AlvinHerawan · Oct 31, 2012 at 06:45 AM

Hi Teon,

I think it is logical for the object thrown to be 'left behind' since both the camera and the character you are aiming for is always moving.

There are 2 possible methods I can think of for now. First one is to make the camera and character walking on the spot and animate all the backgrounds instead. This will still create the illusion of moving without literally moving them in the scene.

Secondly, by instantiating the thrown object as a child of either the camera or the character, which has been described here.

Best of luck!

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 JanWosnitza · Oct 31, 2012 at 08:09 AM 0
Share

I'm not sure if your second approach will work with physics simulated (thrown) objects, maybe saving/tagging all objects and then updating their positions along with the camera's one would be the better choice :)

@Teonnyn if you plan to have physic simulated objects in the background Alvin's first approach wouldn't be a good choice, because this way the whole level is forced to be simulated.

avatar image DevMerlin · Oct 31, 2012 at 09:43 AM 0
Share

Which type of method would be best for a Distance/Launch style game?

avatar image AlvinHerawan · Nov 01, 2012 at 06:16 AM 1
Share

Jan is right, my second suggestion will most probably be not working. Thanks for enlightening.

The best bet would be to move the background ins$$anonymous$$d, then.

avatar image DevMerlin · Nov 01, 2012 at 06:21 AM 0
Share

I decided to take a new approach.. it wasn't working overall.

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

Oblique launch problem 0 Answers

I want the pitcher to throw a ball to a target a location inside a GUI panel 0 Answers

Perfect oblique launch from point A to point B 1 Answer

Rotate object instead of camera around it? 0 Answers

Vector3.SmoothDamp() - smoothTime unit 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