Hello dear friends
I am stuck a few days with jump function here is my idea:
I have a fully working joystick from unity asset working verry well but
i need to make a jump only once when Joystick is pressed or hold to UP.
When I holding the joystick arrow navigate to TOP then player stay flying TOP.
And here is my problem how to i can avoid to it? How set joystick only once jump then wait
a while before another jump how to prevent to holding UP Arrow on it? Here is my script which i trying but
iam stuck here⦠Thanks for anyone who read this a try help me Have a nice day script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class FloatingPlayer2DController : Photon.MonoBehaviour {
public float moveForce=1,boostMultiplier=2;
bool Grounded;
void OnCollisionStay2D(Collision2D collider)
{
CheckIfGrounded ();
}
void OnCollisionExit2D(Collision2D collider)
{
Grounded = false;
}
private void CheckIfGrounded()
{
RaycastHit2D[] hits;
//We raycast down 1 pixel from this position to check for a collider
Vector2 positionToCheck = transform.position;
hits = Physics2D.RaycastAll (positionToCheck, new Vector2 (0, -1), 0.01f);
//if a collider was hit, we are grounded
if (hits.Length > 0) {
Grounded = true;
}
}
Rigidbody2D myBody;
// Use this for initialization
void Start() {
DontDestroyOnLoad(gameObject.transform);
myBody = this.GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void FixedUpdate() {
if(photonView.isMine){
Vector2 moveVec = new Vector2 (CrossPlatformInputManager.GetAxis("Horizontal"),CrossPlatformInputManager.GetAxis("Vertical"));
if (CrossPlatformInputManager.GetAxis("Vertical")>0||Grounded) {
//myBody.AddForce(moveVec);
myBody.AddForce(Vector3.up *moveForce);
return;
} else {
myBody.AddForce(moveVec);
}
}
}
}