Quantcast
Channel: Questions in topic: "jumping"
Viewing all 1225 articles
Browse latest View live

How to make animation and change position at the same time ? ( Example , like MapleStory /Terraria Slime hoping from one place to another )

$
0
0
I have try using animator to animate the jumping animation from one place to another but it seems like it just keep repeating instead of jumping from the place that landed before.

c# PowerUps not working;

$
0
0
Can't seem to get this jump force increase to stop after about 3 secs. public PlayerMovement playerScript; PlayerMovement jumpeForce; public float powerupTimer = 3; public void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { PlayerMovement playerScript = other.gameObject.GetComponent(); if (playerScript) { playerScript.jumpForce = 20; StartCoroutine(PowerUpEnding()); } Destroy(gameObject); } } public IEnumerator PowerUpEnding() { yield return new WaitForSeconds(3f); GetComponent().ResetJumpForce(); } } public float moveSpeed = 5f; public float jumpForce = 10f; public bool isGrounded; //public float coeffSpeedUp = 10; public KeyCode Left; public KeyCode Right; public KeyCode Jump; public Transform groundCheck; public float groundcheckRadius; public LayerMask whatIsGround; private Rigidbody2D rb; // Use this for initialization void Start () { rb = GetComponent(); } // Update is called once per frame void Update () { isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundcheckRadius, whatIsGround); if (Input.GetKeyDown(KeyCode.R)) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } if (Input.GetKey(Left)) { rb.velocity = new Vector2(-moveSpeed, rb.velocity.y); } else if (Input.GetKey(Right)) { rb.velocity = new Vector2(moveSpeed, rb.velocity.y); } else { rb.velocity = new Vector2(0, rb.velocity.y); } if (Input.GetKeyDown(Jump) && isGrounded) { rb.velocity = new Vector2(rb.velocity.x, jumpForce); } if (rb.velocity.x < 0) { transform.localScale = new Vector3(-2, 1, 1); } else if (rb.velocity.x > 0) { transform.localScale = new Vector3(2, 1, 1); } } public void ResetJumpForce () { jumpForce = 10; } }

Varible jump heights

$
0
0
In my 2D game, I'm trying to add variable jump heights but I'm having trouble how to achieve this effect. Here is my script: using UnityEngine; using System.Collections; public class PlayerControl : MonoBehaviour { private CharacterController controller; private float verticalVelocity; private float movement = 1.0f; public bool runControl = false; public float gravity = 60.0f; public float speed = 30.0f; public float jumpForce = 32.0f; public float shortJumpForce = 10.0f; public float soundVolume = 0.75f; private AudioSource source; public AudioClip jump; public static bool moving = true; void Start() { source = GetComponent(); controller = GetComponent (); } void Update() { if (controller.isGrounded) { verticalVelocity = -gravity * Time.deltaTime; if (Input.GetMouseButtonDown (0)) { source.PlayOneShot (jump, soundVolume); verticalVelocity = jumpForce; } } else { verticalVelocity -= gravity * Time.deltaTime; } if (moving) movement = 1; else movement = 0; Vector2 moveVector = new Vector2(0,verticalVelocity); if (runControl) { moveVector.x = movement * speed; } controller.Move(moveVector * Time.deltaTime); } } Thank you for the help.

Score tracker adding too many points per jump

$
0
0
In my game a player receives points every time they make a jump and there should only be one point added per jump. I have the jump() method in the Update() method and this is what the jump method calls. public void jump() { if (checkCanJump()) { myBody.velocity = new Vector2(myBody.velocity.x, jumpSpeed); scoreTracker.scoreCount++; } } checkCanJump() simply ensures that the player is touching the ground and checks to see if the player is touching the screen. When I run the game on the computer the scoring works fine but when I use my iPhone every time I jump receive 2-3 points. Why is this? Thanks!

General Jumping Mechanic Animation Question

$
0
0
I want to have a character jump animation without root motion. I have a stationary jump animation and a standard character controller jump script. The jump script instantly adds vertical velocity when I push the jump button. But the jump animation has an anticipation key frame where they bend their knees to push off. What is the standard method for incorporating this instant of non-vertical velocity into the jump sequence after the jump button is pushed but before the player moves up? Thanks!

jumping from ledge problem

$
0
0
My movement script allows the player to jump 0.1s after going off a ledge so that it seems more realistical. Otherwise he would just slide off the ledge as soon as he reaches it. I have a Capsule with CharacterController. The problem is that the player wont jump sometimes when on ground. It happens just once in 20 times but it happens and it would be irritating if it'd happen at a crucial moment. I tried the code without the ledge tolerance and it works perfectly fine but does someone have an idea how to solve the problem or does someone have an alternative? the tolerance part would be the lines with jumpAllowTime, jumpAllowTimeTrack, waitToLand and waitToLandTrack void Start() { player = GetComponent (); transform.position = spawnPoint.transform.position; jumpSpeed = Mathf.Sqrt (2 * gravity * jumpHeight); verticalSpeed = -gravity; jumpAllowTimeTrack = jumpAllowTime; movementSmoothFactor = groundSmoothFactor; } void Update(){ moveHorizontal = 0; moveDepth = 0; moveSpeed = 1.0f; moveSpeedAir = 0.6f; //input onGroundInput = new Vector3 (moveHorizontal,0,moveDepth); //normalizes the vector so that diagonal movement doesn't get too fast if (onGroundInput.magnitude > 1) { onGroundInput.Normalize(); } targetGroundMovement = onGroundInput; //lets the character walk into the direction the camera is facing targetGroundMovement = playerCamera.transform.TransformDirection (targetGroundMovement); targetGroundMovement.y = 0; targetGroundMovement *= onGroundInput.magnitude; //gravity if (player.isGrounded) { movementSmoothFactor = groundSmoothFactor; jumpAllowTimeTrack = jumpAllowTime; waitToLandTrack -= Time.deltaTime; debugText.text = "grounded"; } if (!player.isGrounded) { movementSmoothFactor = airSmoothFactor; verticalSpeed += Physics.gravity.y * Time.deltaTime; jumpAllowTimeTrack -= Time.deltaTime; waitToLandTrack = waitToLand; debugText.text = "not grounded"; } if (waitToLandTrack < 0.0f) { verticalSpeed = -0.1f; jumpText.text ="not jumping"; } //jumping if ((jumpAllowTimeTrack > 0.0f) && (Input.GetKeyDown(KeyCode.Space))) { verticalSpeed = jumpSpeed; jumpText.text ="jumping"; } } void FixedUpdate () { /*currentMovement converges to targetGroundMovement with time currentMovementVelocity gets processed on every function call*/ currentMovement = Vector3.SmoothDamp (currentMovement, targetGroundMovement * speed, ref currentMovementVelocity, movementSmoothFactor); currentMovement.y = verticalSpeed; player.Move(currentMovement * Time.deltaTime ); }

Air Control While Jumping?

$
0
0
so i'm trying to make a 3rd person platformer. everything works absolutely fine as it is. but what i want to be able to do is control the players direction while he is in the air/jumping. i have tried a lot of things so far and done a bit of research. i just cant seem to figure is out.. now i am only learning i an very new to coding. im just hoping that someone can push me in the right direction to get this to work. Thank-you! [Header("Speed/Movement Settings")] public float crouchSpeed = 2.5f; public float walkSpeed = 5f; public float runSpeed = 10f; public float maxSlopeLimit = 45f; private float speed; //the walk speed of the player [Header("Jumping/Gravity Settings")] public bool doubleJump; //bool for single of double jump public bool airMove; public float jumpForce = 15f; //how fast the player will move up when jumping public float gravity = 35f; //how strong/fast gravity will pull you down public float airControl = 0.25f; [Header("Camera Settings")] public GameObject cam; //the camera used for the player. mainly here for the Up/Down look and Clamp. public float lookSensitivityX = 2f; // sets the sesitvity of the mouse Left/Right public float lookSensitivityY = 0.75f; // sets the sesitvity of the mouse Up/Down public float minLookY = -60f; //clamps the player look Down rotaion minimum public float maxLookY = 75f; //clamps teh player look Up rotaton maximum Vector3 moveDir = Vector3.zero; int jumpTimes; //how many times the player will be able to jump in the air float rotY; //the rotaion of the camera UP/DOWN float rotX; //the rotation of the camera LEFT/RIGHT void Update () // happens every frame { CharacterController controller = gameObject.GetComponent(); // gets the character controller attached to the player. float ih = Input.GetAxisRaw ("Horizontal"); // get the input of the horizontal axis (X) float iv = Input.GetAxisRaw ("Vertical"); // gets the input on the verticle axis (Z) if (controller.isGrounded) // if the player is on the ground { if (Input.GetKey (KeyCode.LeftShift)) //if the Left Shift Key is Held Down Speed will = to Run Speed { speed = runSpeed; controller.center = Vector3.zero; } else if (Input.GetKey (KeyCode.C)) // but if the C key is held down speed will = the couch speed { speed = crouchSpeed; } else //if neither of the above keys are being held down speed will = to the defualt Walk speed { speed = walkSpeed; controller.center = Vector3.zero; } moveDir = new Vector3 (ih, 0, iv).normalized; //seting where we want the axis to be modified and how moveDir = transform.rotation * moveDir.normalized; // allows the player to be able to rotate and the same speed he moves( i think haha ) moveDir *= speed; // sets how fast the player will move jumpTimes = 0; // set jump time to 0 so you are able to jump again } if (!doubleJump) //checks if the double jump bool is FALSE { //Debug.Log ("NormalJump"); // will show if single jump is active (in the console) JumpFunc (); // find and moves through the single jump function } if (doubleJump) //checks if the double jump bool is TRUE { //Debug.Log ("DoubleJump"); // will show if double jump is active (in the console) DoubleJumpFunc (); // find and moves through the double jump function } moveDir.y -= gravity * Time.deltaTime; // this will move the player downward at the speed on gravity. controller.Move(moveDir * Time.deltaTime); // this will allow the player to actually be able to move. Debug.Log (speed); // will show the speed of the player (in the console) controller.slopeLimit = maxSlopeLimit; // this will set the players slope limit to a specified ammount. } void LateUpdate() //happens every other frame? { rotX = Input.GetAxis ("Mouse X") * lookSensitivityX; //Sets up the mouse to look left and right rotY -= Input.GetAxis ("Mouse Y") * lookSensitivityY; //Sets up the mouse to look up and down rotY = Mathf.Clamp (rotY, minLookY, maxLookY); //Clamps the up and down rotation transform.Rotate (0, rotX, 0); //Allows you to look left and right cam.transform.localRotation = Quaternion.Euler(rotY, 0, 0); //Allows you to look up and down (with boundries -- Clamp) } void JumpFunc() //single jump function { if (jumpTimes < 1) //see if the amount of times you have jumped is below 1 { if (Input.GetButtonDown ("Jump")) //see if the space bar has been pressed { moveDir.y = jumpForce; // move you upwards ad the speed of "jump force" jumpTimes += 1; // +'s 1 on to the jump time so then it will be 1 meaning youll be able to jump one more time which will then make jump time = 2 which is not lower then 2. will not be able to jump again till on the ground } } } void DoubleJumpFunc() //double jump function { if (jumpTimes < 2) //see if the amount of times you have jumped is below 2 { if (Input.GetButtonDown ("Jump")) //see if the space bar has been pressed { moveDir.y = jumpForce; // move you upwards ad the speed of "jump force" jumpTimes += 1; // +'s 1 on to the jump time so then it will be 1 meaning youll be able to jump one more time which will then make jump time = 2 which is not lower then 2. will not be able to jump again till on the ground } } } }

Navmesh interfering with mecanim jump animation (root motion)

$
0
0
Hi, My enemy character jumping animation (applied root motion) works on its own. But as soon as I apply Nav Mesh Agent, the character does the animation in the forward direction but not in the upward direction. It seems as if the agent does not allow any motion in the Y-axis. I've tried several animations and followed unity navmesh + mecanim manual. Any suggestions on how to solve this?

Hello! I have infinite jump problem, please help me!

$
0
0
void Update() { if (Input.GetButtonDown("Jump") && isGrounded) { jump = true; jumpForce = 1000; } else { jump = false; jumpForce = 0; } } void FixedUpdate() { isGrounded = Physics2D.OverlapCircle(groundCheck.position, radius, groundLayer); float h = Input.GetAxis("Horizontal"); anim.SetFloat("Speed", Mathf.Abs(h)); if (h * Fb2d.velocity.x < maxSpeed) Fb2d.AddForce(Vector2.right * h * moveForce); if (Mathf.Abs(Fb2d.velocity.x) > maxSpeed) Fb2d.velocity = new Vector2(Mathf.Sign(Fb2d.velocity.x) * maxSpeed, Fb2d.velocity.y); if (h > 0 && !facingRight) Flip(); else if (h < 0 && facingRight) Flip(); if (jump && isGrounded) { if (Fb2d.velocity.y < maxJumpVelocity) { Fb2d.AddForce(Vector2.up * jumpForce); jump = true; jumpForce = 1000; } else { // Otherwise stop jumping jump = false; jumpForce = 0; } } }

Create jumping motion with only transform.Translate

$
0
0
I have an empty 3D GameObject that is serving as the player in a game that I am building. I am trying to write a script that enables the player to "jump" when `SPACE` is pressed. I want to do this using kinematic equations, and with only `transform.Translate`. Here is the code I have so far: public float fallingSpeed; void Update () { if (Input.GetKey (KeyCode.Space)) { Jump (); } } public void Jump () { float yPosition = 0.5f; // Don't let player fall through floor if (transform.position.y <= 0.5f) { fallingSpeed = 0.0f; } else { fallingSpeed -= 9.8f * Time.deltaTime; yPosition += fallingSpeed * Time.deltaTime; } // Translate y-position transform.Translate (new Vector3 (0.0f, yPosition, 0.0f)); } Currently, when `SPACE` is pressed, the player launches into the air and doesn't come back down. I have tried tinkering with the logic for some time, but can't seem to wrap my head around why it's not working. Any help is appreciated! EDIT: it seems as though my player reacts well to the mechanics I have set up... _when_ `SPACE` is held down. As soon as you let go, the player hangs at whatever y-position he is currently situated, and doesn't move until you press `SPACE` again. How do I get him to keep falling even when I let go of `SPACE`? Will that have to be in the `Update()` method? Thanks!

I have range and jump problem!

$
0
0
Hello guys! I have range problem! My problem : I set range to (-5,5), that I can't jump while I in the air and while I don't touch the platform, but my platforms spawning with random method and fall about 1.5f and when fell, then my range change to platform position , so my range not working. public float moveForce = 365f; public float maxSpeed = 7f; public float jumpForce = 1000f; public float maxJumpVelocity = 1f; public float Range; public LayerMask groundLayer; public Transform groundCheck; public bool isGrounded = false; public Text CoinText; public Text WinText; public Text LevelText; private Animator anim; private Rigidbody2D Fb2d; private int count; // Use this for initialization void Awake() { anim = GetComponent(); Fb2d = GetComponent(); count = 0; SetCountText(); WinText.text = ""; Thread.Sleep(1200); } void OnCollisionEnter(Collision2D other) { isGrounded = true; } // Update is called once per frame void Update() { //DeathTrigger if (transform.position.y < -23) Application.LoadLevel(Application.loadedLevel); if (Input.GetButtonDown("Jump") && isGrounded == false) { if (Fb2d.velocity.y < maxJumpVelocity) { Fb2d.AddForce(Vector2.up * jumpForce); } } } void FixedUpdate() { Range = groundCheck.position.y - gameObject.transform.position.y; if (Enumerable.Range(-5, 5).Contains(Mathf.FloorToInt(Range))) { isGrounded = false; } else { isGrounded = true; }

How do you get your player to jump smoothly?

$
0
0
using System.Collections; using System.Collections.Generic; using UnityEngine; public class player_movement : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { float cj = Time.time + 1.5f; float x = Input.GetAxis("Horizontal") * Time.deltaTime * 100.0f; float z = Input.GetAxis("Vertical") * Time.deltaTime * 15.0f; transform.Rotate(0, x, 0); transform.Translate(0, 0, z); if (Input.GetKeyDown("space")) { for (int i = 0; i < 10; i++) { transform.Translate(0, 5, 0); } } } }

Can't control jumping while moving horizontally

$
0
0
Hello, I can't seem to fully control my 2D character's jump while moving horizontally. Sometimes it works perfect and other times, while moving (especially on slopes), it does not. The jump-only and move-only seem to work perfectly all the time but only sometimes when used together. I also notice that the character moves perfectly while in the air. Below is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { [SerializeField] private Transform[] groundPoints; [SerializeField] private float groundRadius; [SerializeField] private LayerMask groundObject; private Rigidbody2D playerRigidbody; private bool groundCheck; public bool jump; public float playerSpeed; public float jumpPower; void Start () { playerRigidbody = GetComponent (); } void FixedUpdate () { float horizontal = Input.GetAxisRaw("Horizontal"); PlayerMovement(horizontal); groundCheck = GroundCheck(); RestValues (); } private void PlayerMovement(float horizontal) { playerRigidbody.velocity = new Vector2(-1 * horizontal * playerSpeed, playerRigidbody.velocity.y); if (horizontal == 0.1) { playerSpeed = 0; } if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) { jump = true; } if (groundCheck && jump) { groundCheck = false; playerRigidbody.AddForce(new Vector2(0, jumpPower)); } } private bool GroundCheck () { if (playerRigidbody.velocity.y <= 0) { foreach (Transform point in groundPoints) { Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, groundObject); for (int i = 0; i < colliders.Length; i++) { if (colliders [i].gameObject != gameObject) { return true; } } } } return false; } private void RestValues () { jump = false; } }

Unity 3D C# dash in backward direction

$
0
0
Hi Ive been trying to get my character to have a "dash" ability to move backwards and cant seem to get it to work. (I am a high school student with no computer science background so I apologize if i make some easy errors) so Ive tried some things such as these and tips on how to make it work? rb.MovePosition(gameObject.transform.position - (Vector3.back * 5)); which got it moving 5 units in a set direction, but not sure how to make this in the "back" direction.

Gravity trouble: Falling slow, jumping fast

$
0
0
I'm a noob so go easy on me. I'm trying to make a simple jump function. Unfortunately, I go up very quickly and come down very slowly. Code is this: void FixedUpdate() { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0F, moveVertical); //Note I'm not adding anything to the y vector here ^ rb.velocity = movement * speed; if (Input.GetKey("space") && detectGround()) { rb.AddForce(0.0F, 1000, 0.0F); //It seems like I'm adding way too much force on y vector, but even with that much I barely leave the ground. I need, like, 10,000 to get a good high jump. } } bool detectGround() { Vector3 down = transform.TransformDirection(Vector3.down); return Physics.Raycast(transform.position, down, .51F); } I'm aware that I might run into weird gravity problems if I'm using odd scales, but I'm dealing with a 1x1x1 sphere in this case. Drag is also not the problem (and if it was, why do I go up so fast?). I've also tried adding some weight to my gravity by changing my y vector. That makes me fall faster but doesn't help the jump any. Interestingly, I don't seem to have this problem if I use rb.AddForce(movement*speed) instead of rb.velocity = movement*speed. Then, however, I don't get the tight control that I want for my X axis and Z axis. (I accelerate too slowly, never hit a peak speed, and have trouble stopping). How do I fix this?

Problem with double jump and characther movement

$
0
0
I'm total noob in coding but im trying to make this character move, jump and double jump. Sometimes my character loose the second jump expecially when i'm moving in some direction on the platform. ![alt text][1] I gave to ferr2d ground a ground layer and my character has a default layer. I have also problem that when i'm falling and im going on a collider I stay on collider and don't fall down![alt text][2]. [1]: /storage/temp/87843-2017-02-11-3.png [2]: /storage/temp/87842-2017-02-11-2.png public float maxSpeed = 10f; public float jumpForce = 10f; bool doubleJump = false; bool grounded = true; public LayerMask playermask; Rigidbody2D rb; SpriteRenderer sr; Animator anim; // Use this for initialization void Start () { rb = GetComponent(); sr = GetComponent(); anim = GetComponent(); } void FixedUpdate () { MovementAnimation(); } void Update() { if (IsGrounded()) { doubleJump = false; } Jump(); } private void OnCollisionEnter2D(Collision2D collision) { grounded = true; } void MovementAnimation() { float move = Input.GetAxis("Horizontal"); anim.SetFloat("Speed", Mathf.Abs(move)); rb.velocity = new Vector2(move * maxSpeed, rb.velocity.y); Flip(move); } void Flip(float move) { if (move > 0) { sr.flipX = false; } else if (move == 0) { sr.flipX = sr.flipX; } else { sr.flipX = true; } } bool IsGrounded() //RayCast che controlla se il pg è a terra quando { Vector2 position = transform.position; Vector2 direction = Vector2.down; float distance = 1.2f; //Distanza dal Suolo Debug.DrawRay(position, direction* distance, Color.green); RaycastHit2D hit = Physics2D.Raycast(position, direction, distance, playermask); if (hit.collider != null) { return true; } return false; } void Jump() { if ((IsGrounded() || doubleJump == true) && Input.GetButtonDown("Jump")) { rb.AddForce(Vector2.up*jumpForce); doubleJump = true; if (doubleJump == true && !IsGrounded()) { doubleJump = false; } } } }

3D FPS jump mechanic and ground detection

$
0
0
This is a 3D, FPS project. I only want my character to be able to jump during the frame the character is touching the ground. This appears to be the working correctly when jumping using only the spacebar. This only appears to be true, because the spacebar input can only be sent so quickly - not every frame. When jumping using mousewheel down, several jump commands are applied to the player, resulting in more vertical force than desired. My assumption is that my player is "on the ground" for more than just a single frame. I added a Jump Debug variable that constantly sends jump commands to help me inspect what is happening frame by frame. It appears as though my player's collider is some times passing through the ground plane. - How can I ensure that the player collider does not pass through the ground plane? - What is the optimal way to detect if the player is in contact with the ground plane? Below are examples of jumping with the space bar, mousewheel down, and with the Jump Debug enabled. Also below is the script (C#) attached to my Player. using System.Collections; using System.Collections.Generic; using UnityEngine; public class characterController : MonoBehaviour { bool onGround = true; public float speed = 10.0f; public bool jumpDebug = false; public void jump() { if (onGround) { this.GetComponent().AddForce(Vector3.up * 200); Debug.Log("single jump"); } } // Use this for initialization void Start() { } // Update is called once per frame void Update() { RaycastHit hit; Vector3 physicsCentre = this.transform.position + this.GetComponent().center; Debug.DrawRay(physicsCentre, Vector3.down*1.02f, Color.red); if (Physics.Raycast(physicsCentre, Vector3.down, out hit, 1.02f)) { if (hit.transform.gameObject.tag != "Player") { onGround = true; } } else { onGround = false; } Debug.Log(onGround); // jump - space if (Input.GetKeyDown("space")) { jump(); } // jump - mousewheeldown if (Input.GetAxis("Mouse ScrollWheel") < 0f) { //Debug.Log("scroll down"); jump(); } // jumpDebug (this will auto jump if enabled, to check if I'm on the ground frame by frame) if (jumpDebug && onGround) { this.GetComponent().AddForce(Vector3.up * 200); } } private void FixedUpdate() { // strafe movement. here instead of Update to reduce jitter when colliding with objects (not sure if this is correct) float forwardBackMovement = Input.GetAxis("Vertical") * speed; float leftRightMovement = Input.GetAxis("Horizontal") * speed; forwardBackMovement *= Time.deltaTime; leftRightMovement *= Time.deltaTime; transform.Translate(leftRightMovement, 0, forwardBackMovement); } } Space bar (desired height) http://i.imgur.com/4U4rjx3.gif Mousewheel Down (erratic height) http://i.imgur.com/sIbf7WB.gif Jump Debug (erratic height) http://i.imgur.com/4PYBJ5o.gif

Jump from the inclined surfaces

$
0
0
I try to add inclined surfaces in my 2d platformer (the tilt of about 30-45 degrees). Character can run on incinclined surfaces well, but I have some troubles with jump from them, because I chek ground using this function: public bool IsGrounded() { if (Math.Abs(MyRigidbody.velocity.y) < 0.1) { foreach (Transform ponint in groundPoints) { Collider2D[] colliders = Physics2D.OverlapCircleAll (ponint.position, groundRadius, whatIsGround); for (int i = 0; i < colliders.Length; i++) if (colliders[i].gameObject != gameObject) { return true;//true if we colliding with smthing } } } return false; } So, obviously, when character "slips" or "climbs" on the surface his |velocity| < 0.1 and he is not on the ground already and can't jump. Yes, I can remove this if statement, but in this case I will be able to jump, when ground not only under the character, but on the side of his ground points too. **How can I fix that problem?** Thnx.

How to stop spam jumping

$
0
0
So I'm trying to make it to where the player cannot just spam the jump so the animation has time to reset, but can't figure out how to do it. using UnityEngine; using System.Collections; public class Character_movement : MonoBehaviour { public Rigidbody rb; private Vector2 forceToAdd = Vector2.zero; private Vector2 jumpForce = Vector2.zero; public float sideToSide = 10f; public float maxSpeed = 5f; public float maxJump = 10f; static Animator ani_1; // Use this for initialization void Start () { ani_1 = GetComponent (); } // Update is called once per frame void Update () { if (Input.GetKey (KeyCode.A)){ if (rb.velocity.y > .1f && rb.velocity.y < -.1f) forceToAdd += new Vector2 (-sideToSide / 10, 0f); else forceToAdd += new Vector2 (-sideToSide, 0f); } if (Input.GetKey (KeyCode.W)) { ani_1.SetTrigger ("W_is_held"); } if (Input.GetKeyDown (KeyCode.A)) { ani_1.SetTrigger ("A_or_D_is_pressed"); } if (Input.GetKeyDown (KeyCode.D)) { ani_1.SetTrigger ("A_or_D_is_pressed"); } if (Input.GetKey (KeyCode.S)) { ani_1.SetTrigger ("S_is_held"); } if (Input.GetKeyUp (KeyCode.A)) { ani_1.SetTrigger ("A_or_D_is_let_go"); } if (Input.GetKeyUp (KeyCode.D)) { ani_1.SetTrigger ("A_or_D_is_let_go"); } if (Input.GetKeyUp (KeyCode.W)) { ani_1.SetTrigger ("W_is_let_go"); } if (Input.GetKeyUp (KeyCode.S)) { ani_1.SetTrigger ("S_is_let_go"); } if (Input.GetKeyDown (KeyCode.W)) { ani_1.SetTrigger ("W_is_pressed"); } if (Input.GetKey (KeyCode.D)) { if (rb.velocity.y > .1f && rb.velocity.y < -.1f) forceToAdd += new Vector2 (sideToSide/10, 0f); else forceToAdd += new Vector2 (sideToSide/2, 0f); } if (Input.GetKeyDown (KeyCode.W) && rb.velocity.y > -0.1f) jumpForce += new Vector2 (0f, maxJump); if (rb.velocity.magnitude < maxSpeed || Mathf.Sign(rb.velocity.x) != Mathf.Sign(forceToAdd.x)) { rb.AddForce (forceToAdd); } rb.AddForce (jumpForce,ForceMode.Impulse) ; jumpForce = Vector2.zero; forceToAdd = Vector2.zero; } }

Increase jump speed colliding on a box ??

$
0
0
(I'm new). I need to jump high ( one shot) when i collide on a box. Someone can help me?
Viewing all 1225 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>