Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Hi recently i've been working on animating my character, and i reached to the parantheses what shoul

Discussion in 'Getting Started' started by njahalshyab72, Sep 11, 2022.

  1. njahalshyab72

    njahalshyab72

    Joined:
    Jul 25, 2022
    Posts:
    8
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class movement : MonoBehaviour
    6. {
    7.     public Animator animator;
    8.      public bool isjumping;
    9.     public float JumpForce=20f;
    10.     public  float speed;
    11.    public Rigidbody2D rb;
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         rb = GetComponent<Rigidbody2D>();
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.  
    22.  
    23.         if(Input.GetButtonDown("Jump")&& isjumping==false)
    24.         {
    25.             Jump();
    26.         }
    27.  
    28.  
    29.  
    30.         [COLOR=#ff0000]animator.SetFloat("speed", Mathf.Abs(????);[/COLOR]
    31.  
    32.  
    33.         rb.velocity= new Vector2(Input.GetAxis("Horizontal") * speed, rb.velocity.y);
    34.  
    35.         if(Input.GetButtonDown("Fire1"))
    36.         {
    37.             rb.velocity = new Vector2(rb.velocity.x, speed);
    38.         }
    39.  
    40.     }
    41.    
    42. void Jump(){
    43.  
    44.     Vector2 movement = new Vector2(rb.velocity.x, JumpForce);
    45.     rb.velocity = movement;
    46. }
    47.  
    48. private void OnCollisionEnter2D(Collision2D other)
    49. {
    50.     if (other.gameObject.CompareTag("Floor"))
    51.     {
    52.         isjumping= false;
    53.     }
    54. }
    55. private void OnCollisionExit2D(Collision2D other)
    56. {
    57.     if (other.gameObject.CompareTag("Floor"))
    58.     {
    59.         isjumping= true;
    60.     }
    61. }
    62.  
    63.    void OnTriggerEnter2D(Collider2D other)
    64.     {
    65.     if (other.gameObject.CompareTag("coins"))
    66.     {
    67.    
    68.     Destroy(other.gameObject);
    69.  
    70.     }
    71.  
    72.  
    73.     }
    74. }
    75.  
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,974
    What is the question exactly?
     
  3. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    I think he's asking if he's done the code right?
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,974
    But there isnt any animation code lol
     
  5. njahalshyab72

    njahalshyab72

    Joined:
    Jul 25, 2022
    Posts:
    8
    i made an animation code colored with blue
    what shall i put in the parantheses
     
  6. njahalshyab72

    njahalshyab72

    Joined:
    Jul 25, 2022
    Posts:
    8
     
  7. njahalshyab72

    njahalshyab72

    Joined:
    Jul 25, 2022
    Posts:
    8
    pls help me fast im in a game jam
     
  8. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,974
    Owhh, that was very unclear lmao
    rb.velocity should be your speed right?
    Otherwise just use trigger animations
     
  9. njahalshyab72

    njahalshyab72

    Joined:
    Jul 25, 2022
    Posts:
    8
    can you send me any example
     
  10. njahalshyab72

    njahalshyab72

    Joined:
    Jul 25, 2022
    Posts:
    8
    im 12 years old
     
  11. njahalshyab72

    njahalshyab72

    Joined:
    Jul 25, 2022
    Posts:
    8
    can you give me examples
    im only 12
     
  12. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,974
    Good that you are starting to code young but I'm not going to do someone elses work
     
  13. njahalshyab72

    njahalshyab72

    Joined:
    Jul 25, 2022
    Posts:
    8
    at least just explain it more
    "im not using you for codes"
     
  14. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,974
    Remove the mathf.abs with RigidBody.velocity if you have an animation setup