How to make hop game?

how to code C# for this game: Unity Asset Store - The Best Assets for Game Making
i don’t have idea to code this game.
I just learn Unity 3d and i want to make this game. i don’t have money to download it.
Hope everyone help me. Thanks.

1 Like

Start here: Learn

4 Likes

You could always beg, borrow or steal the $15. Of course once you had the asset, you probably wouldn’t know what to do with it. Which puts you back at the learn section.

4 Likes

I understand it could be helpful to have some example like this to learn how it work.

But it is a very simple game and you should indeed learn the basis of programming and have a least a rough understanding of how it work globally.

Then you will be able to start creating this game by yourself.

Take a look at Unity examples projects: https://unity3d.com/learn/resources/downloads

1 Like

i just ask algorithm in order to the ball drop exact on platform. i make it but don’t drop on platform anytime.
see my game and tell me how to fix:

distance between 2 platform is 1.5f

Assuming you choose when you jump, you keep an offset if you jump too late:

When you jump, you should always aim the center depth of the next platform so the speed may change smoothly.
You need more control of your ball movements.

Your ball position speed automatically vary on Z Axis by checking next platform Z position, controlled on X Axis and a Mathf.Sin for Y Axis.

For Z speed, you can try something like that:

float distToNext = Mathf.Abs(ballPosition.z - nextPlatformPosition.z);

float zSpeed = speed * Time.deltaTime  * (distToNext / distBetweenPlatforms);

But the ball will gradually slow down while approaching the next platform.

Instead of that, you can also use a Vector3.Lerp function with an AnimationCurve to do a lerp after each jump to have the center of the nextplaform as the destination.

Or you can use a function to predict the velocity needed for a rigidbody to reach a choosed destination:

thanks for helping. but your code apply to ball or platform. My code just platform move Z axis. and the ball does not move z axis. It has rigidbody and jump by this code:
var g = Physics.gravity.magnitude; // get the gravity value
var vSpeed = Mathf.Sqrt(2 * g * jumpHigh); // calculate the vertical speed
rigidbody.velocity = newVector3(0, vSpeed, 0); // jump ball

the ball always has Z = 0.

Well that’s a bad approach to move your platforms instead of your ball. You are moving X objects when you could only move one.

1 Like

i created a parent platform GameObject after that i added child platform into parent platform. i just move parent platform. i just don’t know how to code to the ball drop on each platform at Z = 0.

Unless you’re making an infinite runner in which case you might justify doing it because of floating point precision issues.

That being said you’re still correct that the recommended approach is to move the ball and simply move the world back to origin (0,0,0) every so often which likewise fixes the floating point precision problems while impacting performance less.

1 Like

Moving “only the parent” is still like moving all platforms.

If you really want to keep it like that, everthing I said before is still effective but it will apply to the parent instead of the ball, except for the predicting velocity stuff.

Thank for your helping Fabian-Haquin. And i had a problem. See this:

the problem is:
when i touch on screen and move ball the ball jump lower than dont touch screen. (You can see it at 0:18). I don’t know why met this problem.
this is my jump ball code:

var g = Physics.gravity.magnitude; // get the gravity value
var vSpeed = Mathf.Sqrt(2 * g * jumpHigh); // calculate the vertical speed
ri.velocity = newVector3(0, vSpeed, 0); // jump ball

and this is my move ball code:

void FixedUpdate () {
        //Platform not run, dont rotate ball
        if (GroundController.instance.speedGround > 0)
        {
            // rotate ball
            transform.Rotate(new Vector3(Time.deltaTime * _rotateSpeed, 0, 0));
        }

        if (isDragging)
        {
            //Get mouse position
            var _mousePos = Input.mousePosition;
            _mousePos.z = 10f; // select distanceX = 10 units from the camera
            //Get position mouse in Screen
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(_mousePos);
            Vector3 temp = transform.position;
            //Get new position for ball
            float _newPos =
                (mousePos.x >= transform.position.x) ? mousePos.x - distanceX : distanceX + mousePos.x;
            temp.x = _newPos;
            temp.x =
                Mathf.Clamp(temp.x, GroundController.instance._minPosX,
                            GroundController.instance._maxPosX);
            //distanceY = Mathf.Abs(distanceY - mousePos.y);
            //ri.velocity = new Vector3(0, distanceY * 0.1f, 0);
            transform.position =
                Vector3.Lerp(transform.position, temp, smoothSpeed);
        }
        if (Input.GetMouseButtonDown(0))
        {
            var _mousePos = Input.mousePosition;
            _mousePos.z = 10;
            Vector3 pressPos = Camera.main.ScreenToWorldPoint(_mousePos);
            //Get distanceX beetween ball and the click mouse
            distanceX = Mathf.Abs(pressPos.x - transform.position.x);
            //Start drag mouse
            isDragging = true;
        }
        if (Input.GetMouseButtonUp(0))
        {
            //End drag mouse
            isDragging = false;
        }
    }

Hope you help me.

Where is your vSpeed computed ? Update() ?

You should not handle one axis by using transform.position and another by using the rigidbody.
You have to move both axis by using the rigidbody or the transform…

I think you are overriding your transform Y position somehow when your drag your ball but I don’t know where and when you move your ball on the Y axis so…

void OnCollisionEnter(Collision col){
   if(col.gameObject.tag == "platform"){
       var g = Physics.gravity.magnitude; // get the gravity value
       var vSpeed = Mathf.Sqrt(2 * g * jumpHigh); // calculate the vertical speed
       ri.velocity = newVector3(0, vSpeed, 0); // jump ball
   }
}

i computed vSpeed when the ball touch platform.

I will not find a solution for you but give you tips to find the solution by yourself.

  • Output the ball Y value using Print() or Debug.Log() or display the value on the screen to check if the ball is indeed going less high.
  • Put the Scene view aside with a side-ortho view and use the pause/step buttons to visually see it without perspective deformation.
1 Like

I want to move my 3D gameObject sphere in my game just like Hop game sphere but I don’t want to jump that object I just want to move my gameObject forward on plane surface but it should follow the direction of player’s Finger like this Hop game means How to move 3d Object Along with Finger I have one code on that but using that code object is moving left and right but only when mouse point or touch is on that gameObject only if I touch on screen it not moving

Hi there! Did you resolve that problem? I am having the same issue on my project.
Hope you could help me