Unity Touch Input Camera Follow Jumpy - android

I am trying to create a RTS style game with a camera system similar to Warcraft/Starcraft and the like. I am making the game for Android/iOS. As of now I found two ways to make the camera go where I want it to with touch input. The problem is that either way the camera will move as it should for about a second, then slow down significantly like it is stuck, then speed up again. This process continues and repeats as long as the user is moving the camera. I have tried to put my code in an Update(), FixedUpdate(), and LateUpdate() function. None of this seems to help. I have included a link below to some code which includes both methods, one of which is commented out. As for the reference to "cameraGuide" in the comment near the top, that is an empty game object I placed at (0,0,0) and made the camera as a child of it. In one of the methods the camera must have the script so that when i use transform.localPosition it refers to the cameras position. In the other method the script must be on the empty game object because that is what is actually translated around.
I should also mention that this only occurs when I test my app while it is installed on the Android device itself. When I use Unity Remote to my device it never happens. I have an HTC One M8 running Android 4.4.2.
here is the code:
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
float dragSpeed = 3f;
Vector3 movement = new Vector3(0, 0, 0);
Vector2 deltaPosition;
//script should be on cameraGuide for this code
void Update() {
if (Input.touchCount > 0) {
if (Input.touchCount == 1) {
switch (Input.GetTouch(0).phase) {
case TouchPhase.Began:
break;
case TouchPhase.Moved:
deltaPosition = Input.GetTouch(0).deltaPosition;
movement.x = -deltaPosition.x;
movement.z = -deltaPosition.y;
transform.Translate((movement.x) * dragSpeed * Time.deltaTime, 0, movement.z * dragSpeed * Time.deltaTime);
//if (transform.position.z >= 450 && (movement.z > 0 || movement.x < 0)) {
// transform.Translate(0, 0, 0, Space.Self);
//} else {
//transform.Translate((movement.x) * dragSpeed, 0, movement.z * dragSpeed, Space.Self);
//}
break;
case TouchPhase.Ended:
break;
}
} else if (Input.touchCount == 2) {
Debug.Log("pinching");
}
}
}
//script should be on the camera for this code
//float dragSpeed = 5f;
// Vector3 movement = new Vector3(0, 0, 0);
// Vector2 deltaPosition;
// void Update() {
// if (Input.touchCount > 0) {
// if (Input.touchCount == 1) {
// switch (Input.GetTouch(0).phase) {
// case TouchPhase.Began:
// break;
// case TouchPhase.Moved:
// deltaPosition = Input.GetTouch(0).deltaPosition;
// movement.x = transform.localPosition.x - deltaPosition.x;
// movement.y = transform.localPosition.y;
// movement.z = transform.localPosition.z - deltaPosition.y;
// StartCoroutine(TransitionCamera());
// //transform.localPosition = Vector3.Lerp(transform.position, movement, dragSpeed);
// //transform.Translate((movement.x) * dragSpeed * Time.deltaTime, 0, movement.z * dragSpeed * Time.deltaTime);
// break;
// case TouchPhase.Ended:
// break;
// }
// } else if (Input.touchCount == 2) {
// Debug.Log("pinching");
// }
// }
// }
// IEnumerator TransitionCamera() {
// var t = 0f;
// if (t < 1) {
// t += Time.deltaTime;
// transform.localPosition = Vector3.Lerp(transform.localPosition, movement, t * dragSpeed);
// yield return null;
// }
// }
}
Thank you for any help.

Related

Unity how can i swerve box with use joint?

I want to get an image like in the picture with code. I stacked boxes because i must add joint with code. I want to make the boxes look like this as the character slides left and right smoothly. And how can i smooth swerving control in unity for touch or mouse button?
I tried this codes for movement:
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
firstPos = touch.position;
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
Swerving(touch.position);
}
private void Swerving(Vector2 touch)
{
endPos = touch;
float diff = endPos.x - firstPos.x;
transform.Translate(diff * Time.deltaTime * swerveSpeed, 0, 0);
}
But not smooth swerving.
I tried hinge joint for image. I tried random values to motor,spring etc. But it didnt work i have never used joints.
In general when dealing with physics you shouldn't use transform this break collision detection and other physics related things like your joints etc.
Try and rather go through the Rigidbody using e.g. Rigidbody.MovePosition (or accordingly Rigidbody2D.MovePosition if your are in 2D) within FixedUpdate like e.g.
// or Rigidbody2D depending on your needs
[SerializeField] private Rigidbody _rigidbody;
private Vector2 startPos;
private float movement;
private void Awake()
{
if(!_rigidbody) rigidbody = GetComponent<Rigidbody>();
}
// get user input in Update in general
private void Update()
{
if (Input.touchCount > 0)
{
var touch = Input.GetTouch(0);
switch(touch.phase)
{
case TouchPhase.Began:
startPos = touch.position;
movement = 0;
break;
case TouchPhase.Stationary:
case TouchPhase.Moved:
movement = touch.position.x - startPos.x;
break;
default:
movement = 0;
}
}
}
// Apply Physics in FixedUpdate!
private void FixedUpdate()
{
_rigidbody.MovePosition(_rigidbody.position + Vector3.right * movement * Time.deltaTime * swerveSpeed);
}
However, in general the touch is a 2D pixel space position which might be quite different on different devices.
I would rather translate it into a 3D world space position and use something like e.g.
[SerializeField] private Rigidbody _rigidbody;
[SerializeField] private Camera _mainCamera;
private float _offset;
private Plane? _hitPlane;
private Vector3 _targetPosition;
private void Awake()
{
if (!_rigidbody) _rigidbody = GetComponent<Rigidbody>();
if (!_mainCamera) _mainCamera = Camera.main;
}
// get user input in Update in general
private void Update()
{
_targetPosition = _rigidbody.position;
if (Input.touchCount <= 0)
{
return;
}
var touch = Input.GetTouch(0);
switch (touch.phase)
{
case TouchPhase.Began:
{
// Check if you are touching the character
var ray = _mainCamera.ScreenPointToRay(touch.position);
if (Physics.Raycast(ray, out var hit) && hit.rigidbody == _rigidbody)
{
// create a virtual plane parallel to the camera view
// passing the hit point
_hitPlane = new Plane(-ray.direction, hit.point);
// also store the offset from pivot to the hit point
// we only care about the X axis
_offset = (_rigidbody.position - hit.point).x;
}
break;
}
case TouchPhase.Stationary:
case TouchPhase.Moved:
{
if (_hitPlane.HasValue)
{
// now instead keep ray casting against that virtual plane
var ray = _mainCamera.ScreenPointToRay(touch.position);
if (_hitPlane.Value.Raycast(ray, out var distance))
{
var hitPoint = ray.GetPoint(distance);
_targetPosition.x = hitPoint.x + _offset;
}
}
break;
}
default:
_hitPlane = null;
break;
}
}
// Apply Physics in FixedUpdate!
private void FixedUpdate()
{
_rigidbody.MovePosition(_targetPosition);
}
this makes sure your character is definitely placed on the X axis where you are dragging it without any delays but still complying with physics

In ARCore application using Unity3d, rotate using swipe is not working?

From the below code the zoom is working with two fingers(pinch to zoom) but my rotation is not working using single swipe.For testing i added a text.The text is getting updated with "One touch move" when I swipe the screen.
Cannot understand the zoom is working but the rotation not working.I have downloaded the latest ARcore SDK.I have used the HelloAR example scene to place the object,where HeartModel is where I instantiate on touch when plane is detected.
public class HelloARController : MonoBehaviour
{
/// <summary>
/// The first-person camera being used to render the passthrough camera image (i.e. AR
/// background).
/// </summary>
public Camera FirstPersonCamera;
/// <summary>
/// A prefab for tracking and visualizing detected planes.
/// </summary>
public GameObject DetectedPlanePrefab;
/// <summary>
/// A model to place when a raycast from a user touch hits a plane.
/// </summary>
public GameObject AndyPlanePrefab;
public GameObject HeartModel;
/// <summary>
/// A model to place when a raycast from a user touch hits a feature point.
/// </summary>
public GameObject AndyPointPrefab;
/// <summary>
/// The rotation in degrees need to apply to model when the Andy model is placed.
/// </summary>
private const float k_ModelRotation = 180.0f;
/// <summary>
/// True if the app is in the process of quitting due to an ARCore connection error,
/// otherwise false.
/// </summary>
private bool m_IsQuitting = false;
public static HelloARController helloinstance;
public GameObject ExampleControl;
//To spawn only once
private bool spawned = false;
private void Start()
{
helloinstance = this;
}
/// <summary>
/// The Unity Update() method.
/// </summary>
public void Update()
{
_UpdateApplicationLifecycle();
// If the player has not touched the screen, we are done with this update.
Touch touch;
if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
{
return;
}
// Should not handle input if the player is pointing on UI.
if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
{
return;
}
// Raycast against the location the player touched to search for planes.
TrackableHit hit;
//TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
//TrackableHitFlags.FeaturePointWithSurfaceNormal;
TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinInfinity;
if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit) && spawned==false)
{
// Use hit pose and camera pose to check if hittest is from the
// back of the plane, if it is, no need to create the anchor.
if ((hit.Trackable is DetectedPlane) &&
Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
hit.Pose.rotation * Vector3.up) < 0)
{
Debug.Log("Hit at back of the current DetectedPlane");
}
else
{
// Choose the Andy model for the Trackable that got hit.
GameObject prefab;
if (hit.Trackable is FeaturePoint)
{
//prefab = AndyPointPrefab;
prefab = null;
}
else
{
// prefab = AndyPlanePrefab;
prefab = HeartModel;
}
// Instantiate Andy model at the hit pose.
var andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation);
// Compensate for the hitPose rotation facing away from the raycast (i.e.
// camera).
//andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self);
// andyObject.transform.Rotate(0, 0, 0, Space.Self);
// Create an anchor to allow ARCore to track the hitpoint as understanding of
// the physical world evolves.
var anchor = hit.Trackable.CreateAnchor(hit.Pose);
// Make Andy model a child of the anchor.
andyObject.transform.parent = anchor.transform;
}
spawned = true;
}
}
/// <summary>
/// Check and update the application lifecycle.
/// </summary>
private void _UpdateApplicationLifecycle()
{
// Exit the app when the 'back' button is pressed.
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}
// Only allow the screen to sleep when not tracking.
if (Session.Status != SessionStatus.Tracking)
{
const int lostTrackingSleepTimeout = 15;
Screen.sleepTimeout = lostTrackingSleepTimeout;
}
else
{
Screen.sleepTimeout = SleepTimeout.NeverSleep;
}
if (m_IsQuitting)
{
return;
}
// Quit if ARCore was unable to connect and give Unity some time for the toast to
// appear.
if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
{
_ShowAndroidToastMessage("Camera permission is needed to run this application.");
m_IsQuitting = true;
Invoke("_DoQuit", 0.5f);
}
else if (Session.Status.IsError())
{
_ShowAndroidToastMessage(
"ARCore encountered a problem connecting. Please start the app again.");
m_IsQuitting = true;
Invoke("_DoQuit", 0.5f);
}
}
}
I have added another script for zoom and rotate given below.In the fixed update I use the touch to swipe-one finger rotate on y axis which is not working.But at the same time pinch to zoom is working.**So my doubt is whether the rotation of the model is locked to origin?**Rotate script is given below which is another script(Rotate.cs which I have attached to the prefab)
void FixedUpdate()
{
if (Input.touchCount > 0 && isLocked==true)
{
var touch = Input.GetTouch(0);
if ((Input.touchCount > 0 && Input.touchCount < 2 && Input.GetTouch(0).phase == TouchPhase.Moved) && !EventSystem.current.IsPointerOverGameObject(touch.fingerId) )
{
// Get movement of the finger since last frame
Debug.Log("One touch Move");
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
Messagetxt.text = this.gameObject.name;
this.transform.Rotate(Vector3.up, -touchDeltaPosition.x * rotspeed * Time.deltaTime, Space.World);
}
if (Input.touchCount == 2 && !EventSystem.current.IsPointerOverGameObject(touch.fingerId))
{
// Store both touches.
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
// Find the position in the previous frame of each touch.
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
// Find the magnitude of the vector (the distance) between the touches in each frame.
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
// Find the difference in the distances between each frame.
float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
float scale = deltaMagnitudeDiff * perspectiveZoomSpeed * Time.deltaTime;
Vector3 tt;
tt.x = scale;
tt.y = scale;
tt.z = scale;
if (this.transform.localScale.x > 0 && this.transform.localScale.y > 0 && this.transform.localScale.z > 0)
{
this.transform.localScale += new Vector3(-scale, -scale, -scale);
}
if (this.transform.localScale.x < 1 && this.transform.localScale.y < 1 && this.transform.localScale.z < 1)
{
this.transform.localScale += new Vector3(scale, scale, scale);
}
if (this.transform.localScale.x > 3 && this.transform.localScale.y > 3 && this.transform.localScale.z > 3)
{
this.transform.localScale += new Vector3(scale, scale, scale);
}
}
}
}
public void Lock_Unlock()
{
if (!isLocked)
{
Lock_Unlock_btn.GetComponent<Image>().sprite = Locksprite;
isLocked = true;
// UnityARHitTestExample.InstanceHitManger.m_HitTransform.GetComponent<UnityARHitTestExample>().enabled = false;
HelloARController.helloinstance.ExampleControl.GetComponent<HelloARController>().enabled = false;
hidecanvas.SetActive(false);
}
else
{
Lock_Unlock_btn.GetComponent<Image>().sprite = Unlocksprite;
isLocked = false;
//UnityARHitTestExample.InstanceHitManger.m_HitTransform.GetComponent<UnityARHitTestExample>().enabled = true;
HelloARController.helloinstance.ExampleControl.GetComponent<HelloARController>().enabled = true;
}
}

UNITY3D - Laggy mouselook on android devices

I'm working on an online multiplayer fps game for android devices.
I have 12 player in my game , 6 player in one side and 6 player in other side and they kill each other.
Evrything is fine but there is an issue in my game and that is , When players are in the scene , Mouse look is laggy.
here is my code :
public void MyUpdate()
{
the_time = Time.deltaTime;
if (Input.touches.Length > 0)
{
foreach (Touch t in Input.touches)
{
if (t.position.x > Screen.width / 2)
{
if (t.phase == TouchPhase.Began)
{
delta = t.deltaPosition;
}
if (t.phase == TouchPhase.Began || t.phase == TouchPhase.Moved)
{
delta = -t.deltaPosition;
ROTX_ROTY.x += (delta.y * sensitivityX * current_speed_offset_vertical * the_time);
ROTX_ROTY.y -= delta.x * sensitivityY * current_speed_offset * the_time;
ROTX_ROTY.x = Mathf.Clamp(ROTX_ROTY.x, -clampAngle, clampAngle);
MyTransform.rotation = Quaternion.AngleAxis(ROTX_ROTY.y,Vector3.up);
x_rot_transform.localRotation = Quaternion.AngleAxis(ROTX_ROTY.x, Vector3.right);
}
else if (t.phase == TouchPhase.Ended)
{
delta = t.deltaPosition;
}
}
}
}
}
Anybody knows how can i solve this problem ?
Because this lag is only in my mouse look . Other things like walking, shooting works fine !
Is there any way to I optimize this code for mobiles?
For example I use Quaternion.AngleAxis instead of Quaternion.Euler because it's little faster... But after all this , I have lag every few second in my game.
/////////////////////
UPDATES :
I changed part of my code and change IF statement to switch case , but my problem not solved.
if (Input.touches.Length > 0)
{
foreach (Touch t in Input.touches)
{
if (t.position.x > Screen.width / 2)
{
switch (t.phase)
{
case TouchPhase.Moved:
delta = -t.deltaPosition;
ROTX_ROTY.x += (delta.y * sensitivityX * current_speed_offset_vertical * the_time);
ROTX_ROTY.y -= delta.x * sensitivityY * current_speed_offset * the_time;
ROTX_ROTY.x = Mathf.Clamp(ROTX_ROTY.x, -clampAngle, clampAngle);
MyTransform.rotation = Quaternion.AngleAxis(ROTX_ROTY.y, Vector3.up);
x_rot_transform.localRotation = Quaternion.AngleAxis(ROTX_ROTY.x, Vector3.right);
break;
default:
delta = t.deltaPosition;
break;
}
}
}
}

How can I drag just one object, but not all the objects in Unity? [duplicate]

so as my previous threads show, I am creating a gameObject from sprites images at runtime using this code:
tex = Resources.Load<Texture2D>("pig") as Texture2D;
Sprite sprite = new Sprite();
sprite = Sprite.Create(tex, new Rect(0, 0, 250, 150), new Vector2(0.5f, 0.5f));
GameObject newSprite = new GameObject();
newSprite.AddComponent<Rigidbody2D>();
newSprite.GetComponent<Rigidbody2D>().gravityScale = 0f;
newSprite.AddComponent<ObjectMovement>();
newSprite.AddComponent<SpriteRenderer>();
SR = newSprite.GetComponent<SpriteRenderer>();
SR.sprite = sprite;
As you see I added a script "ObjectMovement", I want to check in this script if someone is dragging this particular gameObject and if so, make it follow the touch position, just to mention - this game is 2D. I never used RaysorRaycast so I am not sure where I gone wrong. Anyway here is my script code:
public SpriteRenderer selection=null;
void Update()
{
if (Input.touchCount >= 1)
{
foreach (Touch touch in Input.touches)
{
Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hit;
switch (touch.phase)
{
case TouchPhase.Began:
if (Physics.Raycast(ray, out hit, 100))
selection = hit.transform.gameObject.GetComponent<SpriteRenderer>();
break;
case TouchPhase.Moved:
selection.transform.position = new Vector2(selection.transform.position.x + touch.position.x / 10, selection.transform.position.y + touch.position.y / 10);
break;
case TouchPhase.Ended:
selection = null;
break;
}
}
}
}
So basically - when touching the screen, fire a ray and check which gameObject is in this position, when moving the finger make it follow it. Drag and drop. Thanks.
EDIT: I noticed the script is attached to every gameObject which is not effective, any ideas?
For 2D, you use RaycastHit2D and Physics2D.Raycast instead of RaycastHit and Physics.Raycast. Those are for 3D. Secondly, Make sure to attach a collider to the Sprite. Since this is a 2D game, the collider must have word "2D" in it. For example, Box Colider 2D from the Editor. You can also use Circle Collider 2D.
I noticed the script is attached to every gameObject which is not
effective, any ideas?
Just create an empty GameObject and attach that script to it. That's it.
Here is fixed version of your code:
float tempZAxis;
public SpriteRenderer selection;
void Update()
{
Touch[] touch = Input.touches;
for (int i = 0; i < touch.Length; i++)
{
Vector2 ray = Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position);
RaycastHit2D hit = Physics2D.Raycast(ray, Vector2.zero);
switch (touch[i].phase)
{
case TouchPhase.Began:
if (hit)
{
selection = hit.transform.gameObject.GetComponent<SpriteRenderer>();
if (selection != null)
{
tempZAxis = selection.transform.position.z;
}
}
break;
case TouchPhase.Moved:
Vector3 tempVec = Camera.main.ScreenToWorldPoint(touch[i].position);
tempVec.z = tempZAxis; //Make sure that the z zxis never change
if (selection != null)
{
selection.transform.position = tempVec;
}
break;
case TouchPhase.Ended:
selection = null;
break;
}
}
}
That would only work on mobile but not on the Desktop Build. I suggest you implement IBeginDragHandler, IDragHandler, IEndDragHandler and override the functions that comes with them. Now, it will work with both mobile and desktop platforms.
Note: For the second solution you have to attach the script below to all Sprites you want to drag unlike the first script above.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Dragger : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
Camera mainCamera;
float zAxis = 0;
Vector3 clickOffset = Vector3.zero;
// Use this for initialization
void Start()
{
//Comment this Section if EventSystem system is already in the Scene
addEventSystem();
mainCamera = Camera.main;
mainCamera.gameObject.AddComponent<Physics2DRaycaster>();
zAxis = transform.position.z;
}
public void OnBeginDrag(PointerEventData eventData)
{
clickOffset = transform.position - mainCamera.ScreenToWorldPoint(new Vector3(eventData.position.x, eventData.position.y, zAxis));
}
public void OnDrag(PointerEventData eventData)
{
//Use Offset To Prevent Sprite from Jumping to where the finger is
Vector3 tempVec = mainCamera.ScreenToWorldPoint(eventData.position) + clickOffset;
tempVec.z = zAxis; //Make sure that the z zxis never change
transform.position = tempVec;
}
public void OnEndDrag(PointerEventData eventData)
{
}
//Add Event Syste to the Camera
void addEventSystem()
{
GameObject eventSystem = new GameObject("EventSystem");
eventSystem.AddComponent<EventSystem>();
eventSystem.AddComponent<StandaloneInputModule>();
}
}

How to jump more or less depending how much time you press the screen in Android (c#)?

I'm doing a game to android with Unity and I don't know how to do to jump more or less depending how much time you press the screen, I tried it but I don't know how to do it, I used deltatime but it doesn't work, at least no at least not in the way I did it, so I would like to know how to do that. The character jumps but just a little bit, it doesn't matter how much time I press the screen, it jumps so low.
This is how I've tried to accomplish that:
void Update () {
movimiento ();
if (transform.position.x <= 4.65f) {
SceneManager.LoadScene ("Game Over");
}
if (Input.touchCount > 0) {
GetComponent<Animator> ().Play ("Andar 2");
print (Input.GetTouch (0).deltaTime);
if (Input.GetTouch (0).deltaTime >= 2) {
GetComponent<Rigidbody2D> ().AddForce (Vector3.up * Time.deltaTime * 20000);
GetComponent<Animator> ().Play ("Andar 2");
} else if (Input.GetTouch (0).deltaTime >= 1) {
GetComponent<Rigidbody2D> ().AddForce (Vector3.up * Time.deltaTime * 2000);
} else if (Input.GetTouch (0).deltaTime < 1) {
GetComponent<Rigidbody2D> ().AddForce (Vector3.up * Time.deltaTime * 200);
}
}
}
I like to work with velocities directly when doing jumps as i feel like i can be more precise with it, But regardless, here is my solution for variable height jumps.
void Update ()
{
// set jump controls
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
jump = true;
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended && !grounded)
jumpCancel = true;
}
void FixedUpdate()
{
// if player presses jump
if (jump)
{
rigidbody.velocity = new Vector3(rigidbody.velocity.x, jumpVelocity, rigidbody.velocity.z);
jump = false;
}
// if player performes a jump cancel
if (jumpCancel)
{
if (rigidbody.velocity.y > shortJumpVelocity)
rigidbody.velocity = new Vector3(rigidbody.velocity.x, shortJumpVelocity, rigidbody.velocity.z);
controller.jumpCancel = false;
}
}
This works by altering the player's velocity if the finger is lifted before the shortJumpVelocity is reached. As you can see you will have to have a grounded state of some kind for this to work properly.
I love this method as it avoids timers and gives the player a lot of control.

Categories

Resources