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 /
  • Help Room /
avatar image
0
Question by Zonda101 · Apr 21, 2017 at 04:06 AM · physics3dvelocitygravitycodepage

3D Aimable Sling Shot

Ok so im trying to make a code that when mouse is clicked and held down the player can drag in the neagtive Y direction to increase the velocity/power in both X and Y. at the same time dragging in the negative X will rotate the aim in the X direction and vise versa. Also the orgin point is the character. I have done tons of reaserch but cant figure this out.

Here is what i have in my actual code using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Flinger : MonoBehaviour {

 // Use this for initialization
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {
    
     EventType.MouseDown 
         {
         EventType.MouseDrag (Vector3)

     }

     
 }

}

And this is what me and my friend have come up with so far.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Flinger : MonoBehaviour {

 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {

     EventType.MouseDown { 
         EventType.MouseDrag (-y= velocity +1 y)
         EventType.MouseDrag (-x= rotation to x, x= rotation to-x)

} } }

I have to go, but hopefully this might help you a little.

THIS IS THE CODE I AM LOOKING AT: double velocity = 20; double angle1 = -30 Math.PI / 180; double angle2 = -60 Math.PI / 180; double vY1 = velocity Math.Sin(angle1); double vX1 = velocity Math.Cos(angle1); double vY2 = velocity Math.Sin(angle2); double vX2 = velocity Math.Cos(angle2); int ball1x = 100, ball1y = 200;//, vY1 = -25, vX1 = 10; int ball2x = 200, ball2y = 150;//, vY2 = -15, vX2 = 15;

         // draw the balls every tenth of a second, for 10 seconds
         for (int ms = 0; ms <= 10000; ms += 100)
         {
             double sec = ms / 1000.0;
             double disp1 = vY1 * sec + 0.5 * 9.81 * Math.Pow(sec, 2);
             g.FillEllipse(Brushes.Blue,
                           (int)(ball1x + vX1 * sec), ball1y + (int)disp1, 10, 10);
             double disp2 = vY2 * sec + 0.5 * 9.81 * Math.Pow(sec, 2);
             g.FillEllipse(Brushes.Blue,
                           (int)(ball2x + vX2 * sec), ball2y + (int)disp2, 10, 10);
             panel.RefreshDisplay();
             System.Threading.Thread.Sleep(20);   // pause for 100 ms
         }
         DrawingPanel.Pause();
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

0 Replies

· Add your reply
  • Sort: 

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

135 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

Related Questions

Gravity on a cube planet 1 Answer

Newtons Cradle Balls? 1 Answer

Using rb.velocity causes low gravity. 2 Answers

how do I find velocity relative to where my player is looking? 2 Answers

Moving and Rotating a Player Smoothly on a Rotating Planet 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