Questions in topic: "parabola"
http://answers.unity.com/questions/topics/single/1123.html
The latest questions for the topic "parabola"How get parabola Angle
http://answers.unity.com/questions/1647244/how-get-parabola-angle.html
Hi.
I want to throw an object into a parabola.
If I had set all the starting points, the end points, the gravity, the weight of the object, would I know the angle of the point of launch?
You'll know I'm bad at math when you see me asking this question.
Please let me know if there is a formula that makes it possible.
Thanks!parabolaWed, 10 Jul 2019 08:55:42 GMTlgs61716[Unity, beginner. Help me.]Fire five parabolic lines in the desired random direction.
http://answers.unity.com/questions/1637144/unity-beginner-help-mefire-five-parabolic-lines-in.html
I've got five places that I've randomly designated.
I want to fire a missile with a parabola.
But it doesn't work the way me want it to.
Video & Code : https://www.youtube.com/watch?v=_8dK8mbeWuE3dgameshootingmissileparabolaSun, 02 Jun 2019 18:37:46 GMTshinemin20Move from A to B using parabola (with or without iTween)
http://answers.unity.com/questions/1515853/move-from-a-to-b-using-parabola-with-or-without-it.html
Hi friends, I want to be able to move something from point A to B using Parabola. I have tried several things but it is not working and I was thinking that perhaps iTween would help but I have no idea where to start with that. I was wondering if there is someone who can help me either with or without iTween to achieve that.
The movement has to be in game, meaning that I select a gameobject (get its transform A) and click somewhere else B to move.
Thanks for your time.itweenmove an objectparabolaFri, 08 Jun 2018 05:50:53 GMTAfassolasTriying to make a character take knockback in a parabolic motion in 2D.
http://answers.unity.com/questions/1510693/triying-to-make-a-character-take-knockback-in-a-pa.html
I'm trying to make a character do a parabolic motion when taking damage but it's not working out.
This is the line of code I have for the movement:
theRB.AddForce(new Vector3(m_jumpX, m_jumpY, transform.position.z), ForceMode2D.Impulse);
Instead of moving in an arc my character is doing the same motion this guy was getting in this reddit thread: https://www.reddit.com/r/Unity2D/comments/57hv0u/unity_2d_knockback/2dphysics2dknockbackarcparabolaFri, 25 May 2018 19:03:16 GMTHeliumBHow to calculate the angle of a trajectory to the target but without gravity and heigh and time
http://answers.unity.com/questions/1501746/how-to-calculate-the-angle-of-a-trajectory-to-the.html
It is even possible? Im trying to make car turns smoothly between paths so I need to dynamic calculate angle of trajectory for wheels. Maybe somebody could explain to me how can I do this? PleaseanglewheelturnparabolaThu, 03 May 2018 18:34:35 GMTWenonCreating a parabola line in 3D Space
http://answers.unity.com/questions/1407064/creating-a-parabola-line-in-3d-space.html
Hello together, i want to create a simple VR teleporter. The teleport destination point and the controller origin should get connected by parabolic line (created by a linerenderer).
What i need is an array of the points on the parabolic line and that the linerenderer takes the rotation of the controller so that it shows the correct rotation.
Here's an example: http://d2ujflorbtfzji.cloudfront.net/key-image/ce95dddc-bef8-493b-bd3e-a872035e0c15.jpg
Trying to get this done already took me two days and it starts driving me crazy. I got the code for 2D working in like 5 mins but i can't port it to 3D especially VR.
Any help would be awesome.mathlinerenderertrigonometryparabolaThu, 14 Sep 2017 12:49:46 GMTJannickLMath Genius NEEDED! Algorithm problem with parabola
http://answers.unity.com/questions/1382704/math-genius-needed-algorithm-problem-with-parabola.html
Hi all, I am trying to make a targeting system with an artillery turret in which there is a set distance, velocity, and gravity acceleration. This targeting system is supposed to calculate the angle in which the turret should fire at to hit the target. I am having some trouble as it is either undershooting or overshooting the target, and am wondering if I have the ratios of real world values like Unity velocity to Real World velocity mixed up or if the equation is wrong. Here is my code:
public class test : MonoBehaviour {
public float angle;
public float g = Physics.gravity.y;
public float v = 1f;
public float d;
public Transform firePoint;
public Transform target;
public TestAAT3 obj;
// Use this for initialization
void Start () {
obj = FindObjectOfType<TestAAT3>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Alpha1))
{
CalculateAngle();
}
}
//d = distance between firepoint and target
//g = gravitational acceleration
//v = given velocity
//angle = theta
public void CalculateAngle()
{
d = Vector3.Distance(firePoint.position, target.position);
angle = (1/2) * Mathf.Asin((g * d) / (Mathf.Pow(v_, 2)));
Debug.Log(d);
obj.Fire(d);
}
}
Any and ALL help is appreciated. I've looked at wikipedia, khan academy videos, etc. Nothing helps!mathanglealgorithmcalculationparabolaSat, 22 Jul 2017 06:09:23 GMTYoshinator2What is the parabolic formula for a 2D projectile's trajectory
http://answers.unity.com/questions/1240338/what-is-the-parabolic-formula-for-a-2d-projectiles.html
I have a little jumping game where the heigh of the jump varies, so to make the game easier, I want to display the trajectory of the jump. To display it I decided to make a while loop that updates a Line Renderer's vertices, given a resolution int of how many vertices I want.
The only problem now is that I don't know how to get the projectile's trajectory as a function/equation. I will have a constant x velocity, and at the beginning of a jump I add a certain upwards-force. I've only been able to find one potentially useful equation, but it requires a force magnitude and an angle.physicsphysics2dmathtrajectoryparabolaWed, 07 Sep 2016 13:48:00 GMTTheShadyColombianmove object with parabola
http://answers.unity.com/questions/1162936/move-object-with-parabola-1.html
i have two points. start and end points .
think like start point is (0,0)
and end point is (4,0)
how can move my object to the target point by parabola pathpositionparabolaparabolicWed, 30 Mar 2016 05:43:44 GMTVeerababu.gI want to create a parabola of collectibles
http://answers.unity.com/questions/1136933/i-want-to-create-a-parabola-of-collectibles.html
I am new to unity. I am working on a demo game. Where we will have a functionality of increasing game over a period of time. I do created a prefabs in parabolic shape for collectibles. As the game speed increased player cannot collect all the coins so I want to increase the distance of parabola as game progression.
Can anyone help me out in better approach or suggestions. So that, I can achieve this functionality.unity 5.netcoinsparabolaTue, 02 Feb 2016 19:34:19 GMTSAnsLeArnErHow to have player fire projectile in a parabola?
http://answers.unity.com/questions/1136198/how-to-have-player-fire-projectile-in-a-parabola.html
Hello, I am trying to figure out a way to have my player fire the projectile in an arc "parabola" like style. Upon hitting the "submit" button I have the player fire a projectile that goes across the screen using the following code.
GetComponent<Rigidbody2D> ().velocity = new Vector2 (speed, GetComponent<Rigidbody2D>().velocity.y);
Vector3 position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,Screen.height,0f));
Sorry not sure what happened with the spacing but anyways, I want the projectile to arc as if they player was throwing a grenade. This is in a 2D game and I have been trying to research parabolas but I am not sure how I would incorporate the formula with this object. I have a transform for the firePoint on the character the projectile instantiates from and I just want the bullet maybe to go about 4 units vertical of the player and 3 units in front of the player, depending on the location of the firePoint each time. Any help is much appreciated, but I am looking for code and an explanation, not just a link to some website explaining parabolas unless it is also a website that explains how to code this in C#.2d gameprojectilearcparabolaMon, 01 Feb 2016 04:11:24 GMTxylofisoLineRenderer: 2D Parabola in 3D Space
http://answers.unity.com/questions/1072025/linerenderer-2d-parabola-in-3d-space.html
Hey all,
I've been working on creating a program that can create a 2D parabola in 3D space (for arcs, and such) but am having some trouble with the third dimension. I've been using this code to generate the parabola:
int i = 0;
while (i < accuracy) {
float z = interval * i;
float y = ((a * (z * z)) + (b * z) + c);
Vector3 position = new Vector3(x * i, y, z + arcCaster.position.z);
arc.Add(position);
i++;
}
...where z is a public float and a, b, and c, can be found by:
a = power;
b = power * h * -2;
c = (power * (h * h)) + maxHeight;
All this is based on the vertex form of the quadratic equation:
a(x-h)^2 + k
or
power(x–HValue())^2 + maxHeight
float HValue () {
return Mathf.Sqrt ((arcCaster.position.y - maxHeight) / (1/-power));
}
Now this gives me a nice arc:
![alt text][1]
[1]: /storage/temp/54990-screen-shot-2015-09-25-at-72531-pm.png
But I cannot rotate this arc. It needs to be able to point in the direction of the cube. My initial thought was to put the positions in a line renderer, set it to local space, and then make the line renderer a child of the cube. But then I realized that I needed those positions for other things, and the positions of the line renderer were in local, not world space.
If I could get the positions of the line renderer and then convert it to world space that would be great. But looking around it doesn't seem like that's possible. Any solutions to this?line rendererarcformulaparabolaMon, 28 Sep 2015 06:38:26 GMTDayyanSissonProjectiles. Simple parabolic path.
http://answers.unity.com/questions/991327/projectiles-simple-parabolic-path.html
I am trying to write a script to allow me to flick an object close to the screen, and it would slide along the z-axis until in reaches a certain point. There will be wind applied to it along the x-axis. Much like "*Paper Toss*"
A few important points. It has to stop in line on the z-axis with the target it's trying to reach.
Like in "*Paper Toss*" it cannot go behind the bin or fall in front of it. It doesn't change it's y-position and last thing, it has to have a parabolic path.
I don't want you to think that I did no work, and I just want someone to write the script, I am just looking for any help I can get. I understand that this is a very simple question but due to my lack of experience with 3d games I can't solve it. I have done a few years of Applied Maths and I understand how the Physics of it works. I just don't know what it the best approach.
Here are my thoughts on it:
1. I cannot simply add an Impulse because I won't have control over where it will stop. Unless I manually type something like (if z <= -10 {stop;} // pseudo code), but that will lead to a sudden stop.
2. I can pre-calculate the path in the following way (look at the .png). The player will drag their finger away from the cross and let go somewhere along the 180 degrees. I can draw a straight line from where he lets the finger go to the target. But that will not feel realistic because even a throw completely to the right will end up in range of sight if you know what I mean.
Please ask a question if you don't understand what I mean at any point.
![alt text][1]
[1]: /storage/temp/48672-untitled.pngparabolaMon, 22 Jun 2015 15:24:27 GMTMax1musDrawing object projected path
http://answers.unity.com/questions/897421/drawing-object-projected-path.html
Hello guys,
Currently I have a soccer game where I set the balls velocity as a vector3 (l/r, up/down/ power) and on click it is hit with that velocity via velocitychange.
At the moment the ball has a LineRenderer which draws the path it will take including gravity, and all is working perfect.
However there is one part I do not know how to implement with maths and that is the relativeVelocity of the object.
The ball has a relativeVelocity (vector3) which is added per frame via addRelativeForce. This function works perfectly, but I just need help in drawing the line it will take including its left right curvature supplied by the relativeVelocity.x.
So at the moment I have a script which draws the parabola using gravity, the ball start pos and the velocity vector =
void DrawMyLine() {
// y = ax^2 + bx + c
// a = grav x = time b = power c = start pos
ballLine.SetVertexCount (rpg_exp);
Vector3[] posArray = new Vector3[rpg_exp];
float a; float b; float c; float d;
float t = 0.0f; float dt = 0.2f;
float gravity = Physics.gravity.y;
float lineRelVel = relativeVelocity.x;
float posArrayLast = 0.0f;
for (int i = 0; i < rpg_exp; i++)
{
a = (gravity/2) * (t*t);
b = velocity.y * t;
c = ballStart.y;
posArray[i].y = a + b + c;
b = velocity.x * t;
c = ballStart.x;
d = lineRelVel * t; //d is the relativeVelocity on x axis
posArray[i].x = b + c + d;
//lineRelVel += posArrayLast;???
b = velocity.z * t;
c = ballStart.z;
posArray[i].z = b + c;
ballLine.SetPosition(i,posArray[i]);
t += dt;
//posArrayLast = posArray[i].x;?
//lineRelVel = posArray[i].x - posArrayLast;???
}
}//drawMyLine
but of course the balls x position changes slightly every frame by relativeVelocity.x, so how do I implement this change into my DrawMyLine function?
Here is what I mean : I want the black line to be where the ball goes.
![alt text][1]
Thanks for your time.
[1]: http://i.imgur.com/57aCfHc.gifmathlinerendererprojectionparabolaTue, 10 Feb 2015 05:01:43 GMTJMEJAY[Maths] How to project a curve in two axis? (Grav y + RelativeVelocity x)
http://answers.unity.com/questions/893761/maths-how-to-make-an-object-follow-a-curve.html
Hello,
I am trying to make an object follow a curved line, and I am using the equation
- ***y = ax^2 + bx + c***
but I am also trying to affect this by a relative velocity value to give it extra curve in the x.
Currently I am inputting these values:
- ***a*** = Gravity (9.81)
- ***x*** = time
- ***b*** = power (5)
- ***c*** (start pos of object.y - 0)
- ***d*** relativeVelocity
void Update () {
//relativeVelocity is found by mouseDelta.x
DrawMyLine();
}
void DrawMyLine() {
// y = ax^2 + bx + c + d
// a = grav x = time b = power c = start pos d = relativeVelocity
ballLine.SetVertexCount (rpg_exp);
Vector3[] posArray = new Vector3[rpg_exp];
float a; float b; float c; float d;
float t = 0.0f; float dt = 0.2f;
float gravity = Physics.gravity.y;
float lineRelVel = relativeVelocity.x;
for (int i = 0; i < rpg_exp; i++)
{
a = (gravity/2) * (t*t);
b = velocity.y * t;
c = ballStart.y;
posArray[i].y = a + b + c;
b = velocity.x * t;
c = ballStart.x;
d = lineRelVel * t; // I added this component, but it is wrong.
posArray[i].x = b + c + d;
lineRelVel += lineRelVel; // What am I doing...
b = velocity.z * t;
c = ballStart.z;
posArray[i].z = b + c;
ballLine.SetPosition(i,posArray[i]);
t += dt;
}
}
![alt text][1]
Thanks for your time.
[1]: /storage/temp/40487-problem.pngmovementmathfollowcurvesparabolaThu, 05 Feb 2015 04:17:18 GMTJMEJAYSet Object X-Rotation to Its Vertical Speed (with a 360º Limit)
http://answers.unity.com/questions/881448/set-object-x-rotation-to-its-vertical-speed-with-a.html
Hello! My name is Juan and there's something I need to put in my game. I want my GameObject to stay parallel/(whatever the name is for 90º intersection, I forget.) to the parabola of movement when jumping. Kinda like this;
![![alt text][1]][1]
[1]: /storage/temp/39209-demo.png
My character is that cat-like thing and the parabola is, well, the parabola of height/distance (neither are accurate).
Thanks in advance to whoever helps!c#rotationscript.parabolaTue, 20 Jan 2015 21:43:32 GMTTheShadyColombianProjectile trajectory calculation for 3 dimensions
http://answers.unity.com/questions/857780/projectile-trajectory-calculation-for-3-dimensions.html
Hey,
I have been able to calculate my trajectory parabola for just axis **y** and **z**. I've been lost recently by trying to comprehend what should it look like in the 3rd dimension. Can't figure it out. I have used the known formula from Newton in order to find height of a point according to its distance. But this formula does't cover the 3rd dimension, unfortunately.
Basically I need my trajectory to be drawn before and till the hit point of my raycast starting from my cam position.
Here is my code, help is appreciated.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Trajectory : MonoBehaviour {
public GameObject point;
public float angle = 30.0f;
public int pointsNum = 30;
public float Vinit = 20.0f;
public List<GameObject> Points = new List<GameObject>();
Vector3 targetPoint = new Vector3(0, 0, 0);
float distance = 0;
void Start()
{
CreatePoints(pointsNum);
}
void Update()
{
PositionPoints();
Debug.Log(CheckAngle() + " ; " + CheckDistance());
}
void CreatePoints(int num)
{
for (int i = 0; i < num; i++)
{
GameObject pointPrefab = Instantiate(point, transform.position, Quaternion.identity) as GameObject;
pointPrefab.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
Points.Add(pointPrefab);
}
}
void PositionPoints()
{
for (int i = 0; i < Points.Count; i++)
{
Points[i].transform.position = new Vector3(0,
1 + CalcHeight(CheckAngle(), (i + (CheckDistance() / Points.Count)), Vinit),
i + (CheckDistance() / Points.Count));
}
}
float CalcHeight(float angle,
float distance,
float Vinit)
{
float Vvert = Vinit * (Mathf.Sin(angle * Mathf.Deg2Rad));
float Vhor = Vinit * (Mathf.Cos(angle * Mathf.Deg2Rad));
float x = distance;
float t = distance / Vhor;
float g = Physics.gravity.y;
float u = Vvert;
float s = (( u * x ) / Vhor ) + 0.5f * g * Mathf.Pow( t, 2 );
return s;
}
float CheckAngle()
{
Vector3 groundVector = Vector3.forward;
Vector3 cameraVector = Camera.main.transform.forward;
float angle = Vector3.Angle(groundVector, cameraVector);
return angle;
}
float CheckDistance()
{
float rayDist = 700.0f;
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, rayDist))
{
Debug.DrawRay(ray.origin, Camera.main.transform.forward * rayDist, Color.red);
targetPoint = hit.point;
distance = hit.distance;
return distance;
}
else
{
return distance;
}
}
}physicsraycastparabolaThu, 18 Dec 2014 21:18:43 GMTgeorge_vasilchenkoPlayer Jump 2D with little parabolic effect.
http://answers.unity.com/questions/779197/player-jump-2d-with-little-parabolic-effect.html
Hi all,
I am creating a 2D game, I wanted to implement jump for my player..like in a parabolic angle..
Currently I am just moving my player to the target position with MoveTowards method. I need to implement parabolic angle to it.
I've attached a screenshot of three objects with my player, now scenario is ..when I click on a gameobject (other than the one on which player is currently) , the player should move above it (like it is at current state) ..with some parabolic angle..with some smooth movements and with some sprite animations,
Please Suggest me how can I make this behaviour. Also I am using NGUI, if this helps..:)![alt text][1]
[1]: /storage/temp/31581-screen+shot+2014-08-27+at+12.05.14+am.png2d-physicsparabolaTue, 26 Aug 2014 19:18:02 GMTsuperbsumitParabolic Movement Equation Problem?
http://answers.unity.com/questions/737808/parabolic-movement-equation-problem.html
Alrighty I have the following problem. I've been moding in Warcraft3 Map Editor for quite a long time and decided to start unity and here are parabolic equations that I've used in W3 and that worked flawlessly:
When both targets inital Y heigths are 0 (requires that both targets are grounded aka their y coordinate is 0):
float Parabola(float h, float d, float x)
{
return (4 * h / d) * (d - x) * (x / d);
}
And the function that takes the initial heights that are different ( for example y0 = 5 and y1 = 0)
float ParabolaInitial(float y0, float y1, float h, float d, float x)
{
float A = (2 * (y0 + y1) - 4 * h) / (d * d);
float B = (y1 - y0 - A * d * d) / d;
return A * x * x + B * x + y0;
}
where x is the localized coordinate towards target, d is the total distance between targets, h is the max height, and y0,y1 respectively height coordinates of start and end target.
This works but gives me the parabola path that is colored red, while I remember that in W3 i was getting green colored parabola path. Red look great but green is the thing that will totaly look incredible and I'm not sure where I'm making a mistake.
Here is the picture:
![alt text][1]
Does anyone has any other parabolic movement codes?
Thank you in advance.
EDIT:
Oh I forgot to state that the problem is that my target is moving, since I am using this formula to make some of the missiles for ranged units have an arc.
[1]: /storage/temp/28472-prob.jpgmovementparabolaMon, 30 Jun 2014 08:47:35 GMTMDarkwingMoving an object's shadow in a straight line below a parabola
http://answers.unity.com/questions/696163/moving-an-objects-shadow-in-a-straight-line-below.html
Hi,
I have a 2D character that jumps across the screen in a parabola. I know the starting position and the target position of the jump.
I want to have a shadow object that tracks the character directly below him. So, the shadow would just move on a straight line between the starting and target positions.
I have the vector necessary by subtracting the starting position from the ending position. What I need is some way to get the position along that vector given the character's position along the parabola. So basically, plug in the character's X position, and get back the shadow's Y position below the character.
Anyone understand the math here well enough to help out? Thank you for any help.vectorparabolaMon, 28 Apr 2014 02:24:27 GMTkathodeWith power and angle, what is the best way to create a parabolic arc?
http://answers.unity.com/questions/631549/with-power-and-angle-what-is-the-best-way-to-creat.html
I'm creating a custom controller for a Launch-type game. My opening sequence is already scripted and produces two variables: Angle, and Power. I do not want to use this with a Rigidbody and physics but create the actual parabolic arc and movement myself - I'm targeting lower-end devices. What kind of formula, or script would be best for this method?
EDIT: My goal is to do this using transform. I've already set up the smoothing in order to handle the movement.
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth);rotationtransformmovement scriptparabolaTue, 04 Feb 2014 00:43:08 GMTDevMerlinmove object with parabola
http://answers.unity.com/questions/540933/move-object-with-parabola.html
I'm trying to figure out how to combine the script with math. What I wanted to achieve is the movement of an object on a parabola. I know the formula of the parabola y= (ax*ax)+bx+c , but how can I apply it to move an object?more as I can point b and c? tanksmovementobjectmathparabolaSat, 21 Sep 2013 18:40:20 GMTBoltParabolic movement doing strange things with certain angles
http://answers.unity.com/questions/458353/parabolic-movement-doing-strange-things-with-certa.html
Hello,
so I'm trying to move a Sphere or whatever in a parabolic trajectory. There is no target or anything, just gravity, angle and speed at which the sphere begins moving.
This is the code I'm using:
using UnityEngine;
using System.Collections;
public class Parabola : MonoBehaviour {
#region Public Variables
public float gravity;
public float angle;
public float speed;
public bool showVel = false;
#endregion
Transform tr;
float time;
Vector3 pos;
void Start() {
tr = transform;
pos = tr.position;
time = 0;
StartCoroutine("ParabolaStart");
}
void FixedUpdate() {
time += Time.deltaTime;
}
IEnumerator ParabolaStart() {
while (true) {
float vel = (speed * Mathf.Sin(angle)) - (gravity * time);
if (showVel)
print ("VEL PARABOLA: "+vel);
float x = 0 + (speed * Mathf.Cos(angle) * time);
float y = 0 + (speed * Mathf.Sin(angle) * time) - (0.5f * gravity * Mathf.Pow(time,2f));
tr.position = new Vector3(x,y,pos.z);
yield return 0;
}
}
void OnCollisionEnter(Collision col) {
print ("Collided with: "+col.transform.name);
StopCoroutine("ParabolaStart");
}
}
The thing, it only seems to work with an angle in the 45~ range. The others I tried don't, the Sphere just slightly moves, if anything at all.
Am I missing something or doesn't it work that way in Unity?c#movementparabolaFri, 17 May 2013 14:36:18 GMTzaaKunposition coins in parabolic path
http://answers.unity.com/questions/436133/position-coins-in-parabolic-path.html
Hi developers,
Please help this new bee.... I want to place the coins in parabolic path (using the parabolic equation) just like the coins placed in subway surfer. I am trying very hard but unable to click the solution.
I am working on game which is similar to Subway Surfer in which the character is running. What kind of explanation is required further?
Your help will be remembered ever. ThankspositionplacementformulaparabolaThu, 11 Apr 2013 10:42:06 GMTtenthplanet0IPhone - Parabola Jump Problem
http://answers.unity.com/questions/260554/iphone-parabola-jump-problem.html
Hi all,
I have been banging my head against the wall for a few days now. Please help me solve this problem.
Its a 2D Game.
So I have a character standing on the screen, and I want the character to jump to a position touched by user, parabolically, without physics..
Perhaps, the easiest way to explain what I am trying to achieve here is that
"How do I get a jumping result similar to the one provided by cocos2D [CCJUMPBY][1]?
Any suggestion please? Thanks a lot
[1]: http://shovon-world.blogspot.com/2011/01/make-jumping-spriteparabolic.html?parabolaThu, 31 May 2012 16:12:34 GMTHeadBangerparabola jump script?
http://answers.unity.com/questions/228054/parabola-jump-script.html
Hello, I am having trouble modifying my movement script for my 2d game.
Jumping is doing well but not as fluid. I was just wondering how/what formula should I use to create a parabolic jumping motion?
<pre>
// Control Scheme:
// Left - A, Left Arrow
// Right - D, Right Arrow
// Crouch - S, Down Arrow
// Run - Shift + Move
// Jump - Spacebar
// Run Jump - Shift + Move + Jump
// Crouch Jump - Down + Jump
var walkSpeed : float = 1.5; // speed of standard walk
var runSpeed : float = 2.0; // speed of run
var walkJump : float = 6.2; // speed of falling down
var runJump : float = 20.0; // jump height from walk
var crouchJump : float = 10.0; // jump height from run
var fallSpeed : float = 2.0; // jump height from crouch
var gravity : float = 20.0; // force applied on char
var startPos : float = 0.0; // location for start position
var moveDirection : int = 1; // direction player facing
var spawnPoint : Transform; // spawn point inherited from Spawn Object
private var velocity : Vector3 = Vector3.zero; // speed of player and direction
function Update ()
{
var controller : CharacterController = GetComponent( CharacterController );
var aniPlay : exSpriteAnimation = GetComponent("exSpriteAnimation");
if ( controller.isGrounded )
{
velocity = Vector3 ( Input.GetAxisRaw ("Horizontal"), 0 , 0 );
//velocity = transform.InverseTransformDirection ( velocity );
//velocity *= walkSpeed;
if ( velocity.x == 0 && moveDirection == 1 ) // idle right
{
if (!aniPlay.IsPlaying("nbreatheright"))
{
aniPlay.Play ( "nbreatheright" );
} // animation to call sprite sheet
}
if ( velocity.x == 0 && moveDirection == 0 ) // idle left
{
if (!aniPlay.IsPlaying("nbreatheleft"))
{
aniPlay.Play ( "nbreatheleft" );
} // animation to call sprite sheet
}
if ( velocity.x > 0) // walk right
{
velocity.x = walkSpeed + 25;
if (!aniPlay.IsPlaying("nrunright"))
{
aniPlay.Play ( "nrunright" );
}
}
if ( (velocity.x > 0) && Input.GetButton ( "Fire1" ) ) // sprint right
{
velocity.x = runSpeed + 50;
if (!aniPlay.IsPlaying("nrunright"))
{
aniPlay.Play ( "nrunright" );
}
}
if ( velocity.x < 0) // walk left
{
velocity.x = -(walkSpeed + 25);
if (!aniPlay.IsPlaying("nrunleft"))
{
aniPlay.Play ( "nrunleft" );
}
}
if ( (velocity.x < 0) && Input.GetButton ( "Fire1" ) ) // sprint left
{
velocity.x = -(runSpeed + 50);
if (!aniPlay.IsPlaying("nrunleft"))
{
aniPlay.Play ( "nrunleft" );
}
}
if ( Input.GetButtonDown ( "Jump" ) && !Input.GetButton ( "Fire1" ) && moveDirection == 1 ) // jump right
{
velocity.y = walkJump + 5;
aniPlay.Play ( "njumpright" );
}
if ( Input.GetButtonDown ( "Jump" ) && Input.GetButton ( "Fire1" ) && moveDirection == 1 ) // high jump right
{
velocity.y = runJump + 10;
aniPlay.Play ( "njumpright" );
}
if ( Input.GetButtonDown ( "Jump" ) && !Input.GetButton ( "Fire1" ) && moveDirection == 0 ) // jump left
{
velocity.y = walkJump + 5;
aniPlay.Play ( "njumpleft" );
}
if ( Input.GetButtonDown ( "Jump" ) && Input.GetButton ( "Fire1" ) && moveDirection == 0 ) // high jump left
{
velocity.y = runJump + 10;
aniPlay.Play ( "njumpleft" );
}
}
if ( (!controller.isGrounded ) && !Input.GetButton ( "Fire1" ) )
{
velocity.x = Input.GetAxis ( "Horizontal" );
velocity.x *= walkSpeed + 10;
}
if ( (!controller.isGrounded ) && Input.GetButton ( "Fire1" ) )
{
velocity.x = Input.GetAxis ( "Horizontal" );
velocity.x *= runSpeed + 10;
}
if ( velocity.x < 0 ) // get last move direction
{
moveDirection = 0; // move direction to left
}
if (velocity.x > 0 ) // get last move direction
{
moveDirection = 1; // move direction to left
}
velocity.y -= gravity * Time.deltaTime; // apply gravity
controller.Move ( velocity * Time.deltaTime ); // move the controller
}
function Awake () {
Spawn ();
}
function Spawn () {
// reset the character's position to the spawnPoint
transform.position = spawnPoint.position;
}
function OnDeath () {
Spawn ();
}
</pre>jumpparabolaFri, 16 Mar 2012 02:05:54 GMTdecoy98Bug Trouble: Spider deviating from parabola path
http://answers.unity.com/questions/223758/bug-trouble-spider-deviating-from-parabola-path.html
Hey everyone,
In the middle of tidying up the last few bugs (that we're aware of :P) in our game before sending it off for review.
I've got one here that is giving me problems simply because I can't reproduce it.
The core idea is I've got a spider game object that moves in a pendulum-like fashion (parabola curve.) The object has a simple box collider for hit-detection and moves back and forth between two set points. Occasionally, one of the spiders will deviate from the course and move straight up along the Y-axis. I'm at a loss as to what could cause this. Any ideas?
using UnityEngine;
using System.Collections;
public class swingSpider : MonoBehaviour {
public Transform start;
public Transform end;
public bool startToFinish;
public bool finishToStart;
public float slerpStartTime;
public float speed;
public float height;
public float verticalVelocity;
public float swingLength;
public float swingPower;
public float distance;
//public float swingTime;
public float curTime;
public float waitTime;
public float time;
GameObject spider;
//public GameObject A;
//public GameObject B;
Vector3 spiderPos;
Vector3 startPos;
Vector3 endPos;
// Use this for initialization
void Start ()
{
startPos = start.transform.position;
endPos = end.transform.position;
startToFinish = true;
slerpStartTime = Time.time;
transform.position = start.position;
}
// Update is called once per frame
void Update ()
{
if(startToFinish == true)
{
time -= Time.deltaTime;
if(time <= 0)
{
distance = Vector3.Distance(transform.position, endPos);
if(distance > 0.1f)
{
height += verticalVelocity * Time.deltaTime;
verticalVelocity = Mathf.Lerp(swingPower, -swingPower, (Time.time - slerpStartTime) * speed);
Vector3 basePos = Vector3.Lerp(startPos, endPos, ((Time.time - slerpStartTime) * speed));
Vector3 resultantPos = basePos + (Vector3.down * height);
transform.position = resultantPos;
}
if(distance <= 0.1f)
{
ResetA();
}
}
}
if (finishToStart == true)
{
time -= Time.deltaTime;
if(time <= 0)
{
distance = Vector3.Distance(transform.position, startPos);
if(distance > 0.1f)
{
height += verticalVelocity * Time.deltaTime;
verticalVelocity = Mathf.Lerp(swingPower, -swingPower, (Time.time - slerpStartTime) * speed);
Vector3 basePos = Vector3.Lerp(endPos, startPos, ((Time.time - slerpStartTime) * speed));
Vector3 resultantPos = basePos + (Vector3.down * height);
transform.position = resultantPos;
}
if(distance <= 0.1f)
{
ResetB();
}
}
}
}
void ResetA()
{
if(startToFinish == true)
{
startToFinish = false;
time = waitTime;
slerpStartTime = Time.time + waitTime;
transform.position = end.position;
distance = 0;
finishToStart = true;
}
}
void ResetB()
{
if(finishToStart == true)
{
finishToStart = false;
time = waitTime;
slerpStartTime = Time.time + waitTime;
transform.position = start.position;
distance = 0;
startToFinish = true;
}
}
}c#parabolaMon, 05 Mar 2012 06:36:45 GMTBlacKatFever