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();
Your answer
Follow this Question
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