• 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 /
This question was closed Mar 24, 2013 at 02:58 PM by robertbu for the following reason:

Duplicate Question

avatar image
0
Question by helloiam · Mar 24, 2013 at 02:18 PM · directionsmoothshootfirecannonball

Last time cannonball fire physics.

Hi guys I want to create a game that when I click on the screen a ball goes smoothly to my mouse position, I did a little scripting and it works but what this script of mine does is when I click on the screen it is going immediately to my mouse position, what I really want is that you have a begin position like in the middle of the screen and then whe I click it goes to my mouse position, so my mouse position is the end.

See this video to understand my problem: http://www.youtube.com/watch?v=gzdI4HmsF0Q

NOTE:

spot.position is the position is the begin position and pos is the end position. I did tried Vector3.lerp and .MovePosition and I tried AddForce but with Vector3.Lerp and MovePosition it works but as i wrote before it goes immediately to the end point which is my mouse position I want that it goes like this video:

http://www.youtube.com/watch?v=c27BK927-TE

Please take a look and help me out, this is really important for me.

Thanks in advance guys!

A little script of mine:

 void shootInput()
     {
         cannonShot.Play();
 
         journeyLength = Vector3.Distance(spot.position, pos);
 
         float distCovered = (Time.time - startTime) * 20f;
         float fracJourney = distCovered / journeyLength;
 
         depth = 15f;
 
         pos = Camera.main.ScreenPointToRay(Input.mousePosition).GetPoint(depth);
 
         Rigidbody ball = Instantiate(cannonBall, spot.position, Quaternion.identity) as Rigidbody;
 
         ball.rigidbody.MovePosition(Vector3.Lerp(spot.position, pos, fracJourney));
 
         // ball.rigidbody.AddForce(transform.forward * 200);
         // ball.rigidbody.AddForce(transform.up * 500);
 
         cannonTop.transform.LookAt(pos);
     }
Comment
Add comment · Show 1
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 · Mar 24, 2013 at 02:59 PM 0
Share

Duplicate of:

http://answers.unity3d.com/questions/423615/cannonball-physics.html#answer-423763

0 Replies

  • Sort: 

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Cannonball physics? 1 Answer

Got confused about logic over an FPS game. Gun pointing, laser sight, raycasting etc. 1 Answer

My gun won't fire. ( Javascript ) 1 Answer

Spray Shot Script 3 Answers

Shoot a bomb to mouse position smooth 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