Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

does anyone have code to make a sphere jump that will work with my code i wrote

Discussion in 'Scripting' started by itspicklerickandmorty, Apr 7, 2020.

  1. itspicklerickandmorty

    itspicklerickandmorty

    Joined:
    Apr 6, 2020
    Posts:
    16
    the code at the bottom can be removed if you want to remove it or you can add or modify it
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Moveball : MonoBehaviour
    6. {
    7.     Rigidbody rb;
    8.     public int ballspeed = 0;
    9.     public int jumpspeed = 0;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         rb = GetComponent<Rigidbody>();
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         float Hmove = Input.GetAxis ("Horizontal");
    20.         float Vmove = Input.GetAxis ("Vertical");
    21.  
    22.         Vector3 ballmove = new Vector3(Hmove, 0.0f, Vmove);
    23.         rb.AddForce (ballmove * ballspeed);
    24.  
    25.         if(Input.GetKey(KeyCode.Space));
    26.         {
    27.             Vector3 balljump = new Vector3 (0.0f, 1.0f, 0.0f);
    28.             rb.AddForce(balljump * ballspeed);
    29.  
    30.         }
    31.     }
    32. }
    33.  
    34.  
    35.  
     
  2. LatchGameDev

    LatchGameDev

    Joined:
    Nov 24, 2014
    Posts:
    61
    I wrote out a whole script for you in another thread that you made titled "I need help with my code for jumping" So link to that is here
    https://forum.unity.com/threads/i-need-help-with-my-code-for-jumping.862033/

    But also don't make two threads for the same issue. Also as a said in that other thread your going to want to take a step back and learn the basics of programming. It will save you so much frustration in the long run.


    Best of luck to you.
     
    Yoreki likes this.
  3. itspicklerickandmorty

    itspicklerickandmorty

    Joined:
    Apr 6, 2020
    Posts:
    16
    I know but the ball just floated away so i want to rewrite it